Audio cd whithout cdfs support.
authorchristophecvr <stefansat@telenet.be>
Sun, 4 Oct 2015 10:52:31 +0000 (12:52 +0200)
committerMike Looijmans <milo-software@users.sourceforge.net>
Sun, 4 Oct 2015 16:46:10 +0000 (18:46 +0200)
Audio CD now working without kernel-module-cdfs.

Signed-off-by: Mike Looijmans <milo-software@users.sourceforge.net>
(changed commit comments)

lib/python/Components/Harddisk.py
lib/python/Components/Scanner.py
lib/python/Plugins/Extensions/MediaPlayer/plugin.py
lib/python/Plugins/SystemPlugins/Hotplug/plugin.py
lib/service/servicemp3.cpp

index 30d9938..38ec89c 100644 (file)
@@ -713,6 +713,25 @@ class HarddiskManager:
                                SystemInfo["Harddisk"] = True
                return error, blacklisted, removable, is_cdrom, partitions, medium_found
 
+       def addHotplugAudiocd(self, device, physdev = None):
+               # device is the device name, without /dev
+               # physdev is the physical device path, which we (might) use to determine the userfriendly name
+               if not physdev:
+                       dev, part = self.splitDeviceName(device)
+                       try:
+                               physdev = os.path.realpath('/sys/block/' + dev + '/device')[4:]
+                       except OSError:
+                               physdev = dev
+                               print "couldn't determine blockdev physdev for device", device
+               error, blacklisted, removable, is_cdrom, partitions, medium_found = self.getBlockDevInfo(device)
+               if not blacklisted and medium_found:
+                       description = self.getUserfriendlyDeviceName(device, physdev)
+                       p = Partition(mountpoint = "/media/audiocd", description = description, force_mounted = True, device = device)
+                       self.partitions.append(p)
+                       self.on_partition_list_change("add", p)
+                       SystemInfo["Harddisk"] = False
+               return error, blacklisted, removable, is_cdrom, partitions, medium_found
+
        def removeHotplugPartition(self, device):
                for x in self.partitions[:]:
                        if x.device == device:
index bd5e2aa..c9310bd 100644 (file)
@@ -21,6 +21,8 @@ def getType(file):
                # Detect some unknown types
                if file[-12:].lower() == "video_ts.ifo":
                        return "video/x-dvd"
+               if file == "/media/audiocd/cdplaylist.cdpls":
+                       return "audio/x-cda"
 
                p = file.rfind('.')
                if p == -1:
@@ -132,7 +134,7 @@ def scanDevice(mountpoint):
                for root, dirs, files in os.walk(path):
                        for f in files:
                                path = os.path.join(root, f)
-                               if is_cdrom and f.endswith(".wav") and f.startswith("track"):
+                               if (is_cdrom and f.endswith(".wav") and f.startswith("track")) or f == "cdplaylist.cdpls":
                                        sfile = ScanFile(path,"audio/x-cda")
                                else:
                                        sfile = ScanFile(path)
index b1d377c..91e5934 100644 (file)
@@ -1,4 +1,4 @@
-import os
+import os, os.path
 from time import strftime
 from enigma import iPlayableService, eTimer, eServiceCenter, iServiceInformation, ePicLoad
 from ServiceReference import ServiceReference
@@ -613,8 +613,8 @@ class MediaPlayer(Screen, InfoBarBase, InfoBarScreenSaver, InfoBarSeek, InfoBarA
                        self.playlist.clear()
                        self.savePlaylistOnExit = False
                        self.isAudioCD = True
-                       for file in self.cdAudioTrackFiles:
-                               ref = eServiceReference(4097, 0, file)
+                       for x in self.cdAudioTrackFiles:
+                               ref = eServiceReference(4097, 0, x)
                                self.playlist.addFile(ref)
                        try:
                                from Plugins.Extensions.CDInfo.plugin import Query
@@ -973,22 +973,19 @@ class MediaPlayer(Screen, InfoBarBase, InfoBarScreenSaver, InfoBarSeek, InfoBarA
                self.session.open(SubtitleSelection, self)
 
        def hotplugCB(self, dev, media_state):
-               if dev == harddiskmanager.getCD():
-                       if media_state == "1":
-                               from Components.Scanner import scanDevice
-                               devpath = harddiskmanager.getAutofsMountpoint(harddiskmanager.getCD())
-                               self.cdAudioTrackFiles = []
-                               res = scanDevice(devpath)
-                               list = [ (r.description, r, res[r], self.session) for r in res ]
-                               if list:
-                                       (desc, scanner, files, session) = list[0]
-                                       for file in files:
-                                               if file.mimetype == "audio/x-cda":
-                                                       self.cdAudioTrackFiles.append(file.path)
-                       else:
-                               self.cdAudioTrackFiles = []
-                               if self.isAudioCD:
-                                       self.clear_playlist()
+               if media_state == "audiocd" or media_state == "audiocdadd":
+                       self.cdAudioTrackFiles = []
+                       list = open("/media/audiocd/cdplaylist.cdpls")
+                       if list:
+                               self.isAudioCD = True
+                               for x in list:
+                                       xnon = x.replace("\n", "")
+                                       self.cdAudioTrackFiles.append(xnon)
+                               self.playAudioCD()
+               else:
+                       self.cdAudioTrackFiles = []
+                       if self.isAudioCD:
+                               self.clear_playlist()
 
 class MediaPlayerLCDScreen(Screen):
        skin = (
@@ -1054,10 +1051,31 @@ def filescan_open(list, session, **kwargs):
 
 def audioCD_open(list, session, **kwargs):
        from enigma import eServiceReference
+       mp = session.open(MediaPlayer)
+       list = open("/media/audiocd/cdplaylist.cdpls")
+       if list:
+               mp.isAudioCD = True
+               for x in list:
+                       xnon = x.replace("\n", "")
+                       mp.cdAudioTrackFiles.append(xnon)
+               mp.playAudioCD()
+       else:
+               # to do : addings msgbox to inform user about failure of opening audiocd.
+               return False
 
+def audioCD_open_mn(session, **kwargs):
+       from enigma import eServiceReference
        mp = session.open(MediaPlayer)
-       mp.cdAudioTrackFiles = [f.path for f in list]
-       mp.playAudioCD()
+       list = open("/media/audiocd/cdplaylist.cdpls")
+       if list:
+               mp.isAudioCD = True
+               for x in list:
+                       xnon = x.replace("\n", "")
+                       mp.cdAudioTrackFiles.append(xnon)
+               mp.playAudioCD()
+       else:
+               # to do : addings msgbox to inform user about failure of opening audiocd.
+               return False
 
 def movielist_open(list, session, **kwargs):
        if not list:
@@ -1077,6 +1095,14 @@ def movielist_open(list, session, **kwargs):
                config.movielist.last_videodir.value = path
                InfoBar.instance.showMovies(eServiceReference(stype, 0, f.path))
 
+def audiocdscan(menuid, **kwargs):
+       from Plugins.SystemPlugins.Hotplug.plugin import AudiocdAdded
+       if menuid == "mainmenu" and (AudiocdAdded() or os.path.isfile('/media/audiocd/cdplaylist.cdpls')):
+               list = ['/media/audiocd/cdplaylist.cdpls']
+               return [(_("Play audio-CD..."), audioCD_open_mn, "play_cd", 45)]
+       else:
+               return []
+
 def filescan(**kwargs):
        from Components.Scanner import Scanner, ScanPath
        return [
@@ -1125,5 +1151,6 @@ def Plugins(**kwargs):
        return [
                PluginDescriptor(name = _("Media player"), description = _("Play back media files"), where = PluginDescriptor.WHERE_PLUGINMENU, needsRestart = False, fnc = main),
                PluginDescriptor(name = _("Media player"), where = PluginDescriptor.WHERE_FILESCAN, needsRestart = False, fnc = filescan),
+               PluginDescriptor(name = _("Media player"), where = PluginDescriptor.WHERE_MENU, needsRestart = False, fnc = audiocdscan),
                PluginDescriptor(name = _("Media player"), description = _("Play back media files"), where = PluginDescriptor.WHERE_MENU, needsRestart = False, fnc = menu)
        ]
index 97ba058..0809064 100644 (file)
@@ -1,15 +1,26 @@
 from Plugins.Plugin import PluginDescriptor
 from Components.Harddisk import harddiskmanager
 from twisted.internet.protocol import Protocol, Factory
+import os, os.path
 
+# globals
 hotplugNotifier = []
+audiocd = False
+
+def AudiocdAdded():
+       global audiocd
+       if audiocd:
+               return True
+       else:
+               return False
 
 def processHotplugData(self, v):
-       print "hotplug:", v
+       print "[Hotplug.plugin.py]:", v
        action = v.get("ACTION")
        device = v.get("DEVPATH")
        physdevpath = v.get("PHYSDEVPATH")
        media_state = v.get("X_E2_MEDIA_STATUS")
+       global audiocd
 
        dev = device.split('/')[-1]
 
@@ -17,6 +28,29 @@ def processHotplugData(self, v):
                error, blacklisted, removable, is_cdrom, partitions, medium_found = harddiskmanager.addHotplugPartition(dev, physdevpath)
        elif action == "remove":
                harddiskmanager.removeHotplugPartition(dev)
+       elif action == "audiocdadd":
+               audiocd = True
+               media_state = "audiocd"
+               error, blacklisted, removable, is_cdrom, partitions, medium_found = harddiskmanager.addHotplugAudiocd(dev, physdevpath)
+               print "[Hotplug.plugin.py] AUDIO CD ADD"
+       elif action == "audiocdremove":
+               audiocd = False
+               file = []
+               # Removing the invalid playlist.e2pls If its still the audio cd's list
+               # Default setting is to save last playlist on closing Mediaplayer.
+               # If audio cd is removed after Mediaplayer was closed,
+        # the playlist remains in if no other media was played.
+               if os.path.isfile('/etc/enigma2/playlist.e2pls'):
+                       with open('/etc/enigma2/playlist.e2pls', 'r') as f:
+                               file = f.readline().strip()
+               if file:
+                       if '.cda' in file:
+                               try:
+                                       os.remove('/etc/enigma2/playlist.e2pls')
+                               except OSError:
+                                       pass
+               harddiskmanager.removeHotplugPartition(dev)
+               print "[Hotplug.plugin.py] REMOVING AUDIOCD"
        elif media_state is not None:
                if media_state == '1':
                        harddiskmanager.removeHotplugPartition(dev)
@@ -32,16 +66,15 @@ def processHotplugData(self, v):
 
 class Hotplug(Protocol):
        def connectionMade(self):
-               print "HOTPLUG connection!"
+               print "[Hotplug.plugin.py] connection!"
                self.received = ""
 
        def dataReceived(self, data):
-               print "hotplug:", data
                self.received += data
-               print "complete", self.received
+               print "[Hotplug.plugin.py] complete", self.received
 
        def connectionLost(self, reason):
-               print "HOTPLUG connection lost!"
+               print "[Hotplug.plugin.py] connection lost!"
                data = self.received.split('\0')[:-1]
                v = {}
                for x in data:
@@ -52,9 +85,7 @@ class Hotplug(Protocol):
 
 def autostart(reason, **kwargs):
        if reason == 0:
-               print "starting hotplug handler"
                from twisted.internet import reactor
-               import os
                try:
                        os.remove("/tmp/hotplug.socket")
                except OSError:
index e3d6ec0..9dd2266 100644 (file)
@@ -486,7 +486,9 @@ eServiceMP3::eServiceMP3(eServiceReference ref):
                m_sourceinfo.audiotype = atMP3;
        else if ( strcasecmp(ext, ".wma") == 0 )
                m_sourceinfo.audiotype = atWMA;
-       else if ( (strncmp(filename, "/media/sr", 9) || strncmp(filename+strlen(filename)-13, "/track-", 7) || strcasecmp(ext, ".wav")) == 0 )
+       else if ( strcasecmp(ext, ".wav") == 0 )
+               m_sourceinfo.audiotype = atPCM;
+       else if ( strcasecmp(ext, ".cda") == 0)
                m_sourceinfo.containertype = ctCDA;
        if ( strcasecmp(ext, ".dat") == 0 )
        {
@@ -528,7 +530,7 @@ eServiceMP3::eServiceMP3(eServiceReference ref):
        }
        else if ( m_sourceinfo.containertype == ctCDA )
        {
-               int i_track = atoi(filename+17);
+               int i_track = atoi(filename+(strlen(filename) - 6));
                uri = g_strdup_printf ("cdda://%i", i_track);
        }
        else if ( m_sourceinfo.containertype == ctVCD )