Пример #1
0
    def test_normalized_metadata(self):
        #Recorded show test first
        orig = Metadata.airtime_dict({
                'date'        : [u'2012-08-21'],
                'tracknumber' : [u'2'],
                'title'       : [u'record-2012-08-21-11:29:00'],
                'artist'      : [u'Airtime Show Recorder']
        })
        orga = Metadata.airtime_dict({
                'date'        : [u'2012-08-21'],
                'tracknumber' : [u'2'],
                'artist'      : [u'Airtime Show Recorder'],
                'title'       : [u'record-2012-08-21-11:29:00']
        })
        orga['MDATA_KEY_FTYPE']   = u'audioclip'
        orig['MDATA_KEY_BITRATE'] = u'256000'
        orga['MDATA_KEY_BITRATE'] = u'256000'
        old_path   = "/home/rudi/recorded/2012-08-21-11:29:00.ogg"
        normalized = mmp.normalized_metadata(orig, old_path)
        normalized['MDATA_KEY_BITRATE'] = u'256000'

        self.assertEqual( orga, normalized )

        organized_base_name = "11:29:00-record-256kbps.ogg"
        base                = "/srv/airtime/stor/"
        organized_path      = mmp.organized_path(old_path,base, normalized)
        self.assertEqual(os.path.basename(organized_path), organized_base_name)
Пример #2
0
    def handle(self, sender, event):
        """ Intercept events where a new file has been added to the
        organize directory and place it in the correct path (starting
        with self.target_path) """
        # Only handle this event type
        assert isinstance(event, OrganizeFile), \
            "Organizer can only handle OrganizeFile events.Given '%s'" % event
        try:
            # We must select the target_path based on whether file was recorded
            # by airtime or not.
            # Do we need to "massage" the path using mmp.organized_path?
            target_path = self.recorded_path if event.metadata.is_recorded() \
                                             else self.target_path
            # nasty hack do this properly
            owner_id = mmp.owner_id(event.path)
            if owner_id != -1:
                target_path = os.path.join(target_path, unicode(owner_id))

            mdata = event.metadata.extract()
            new_path = mmp.organized_path(event.path, target_path, mdata)

            # See hack in mmp.magic_move
            def new_dir_watch(d):
                # TODO : rewrite as return lambda : dispatcher.send(...
                def cb():
                    dispatcher.send(signal=getsig("add_subwatch"),
                                    sender=self,
                                    directory=d)

                return cb

            mmp.magic_move(event.path,
                           new_path,
                           after_dir_make=new_dir_watch(dirname(new_path)))

            # The reason we need to go around saving the owner in this
            # backwards way is because we are unable to encode the owner id
            # into the file itself so that the StoreWatchListener listener can
            # detect it from the file
            user().owner.add_file_owner(new_path, owner_id)

            self.logger.info('Organized: "%s" into "%s"' %
                             (event.path, new_path))
        except BadSongFile as e:
            self.report_problem_file(event=event, exception=e)
        # probably general error in mmp.magic.move...
        except Exception as e:
            self.unexpected_exception(e)
            self.report_problem_file(event=event, exception=e)
Пример #3
0
    def handle(self, sender, event):
        """
        Intercept events where a new file has been added to the organize
        directory and place it in the correct path (starting with
        self.target_path)
        """
        # Only handle this event type
        assert isinstance(event, OrganizeFile), \
            "Organizer can only handle OrganizeFile events.Given '%s'" % event
        try:
            # We must select the target_path based on whether file was recorded
            # by airtime or not.
            # Do we need to "massage" the path using mmp.organized_path?
            target_path = self.recorded_path if event.metadata.is_recorded() \
                                             else self.target_path
            # nasty hack do this properly
            owner_id = mmp.owner_id(event.path)
            if owner_id != -1:
                target_path = os.path.join(target_path, unicode(owner_id))

            mdata = event.metadata.extract()
            new_path = mmp.organized_path(event.path, target_path, mdata)

            # See hack in mmp.magic_move
            def new_dir_watch(d):
                # TODO : rewrite as return lambda : dispatcher.send(...
                def cb():
                    dispatcher.send(signal="add_subwatch", sender=self,
                            directory=d)
                return cb

            mmp.magic_move(event.path, new_path,
                    after_dir_make=new_dir_watch(dirname(new_path)))

            # The reason we need to go around saving the owner in this ass
            # backwards way is bewcause we are unable to encode the owner id
            # into the file itself so that the StoreWatchListener listener can
            # detect it from the file
            owners.add_file_owner(new_path, owner_id )

            self.logger.info('Organized: "%s" into "%s"' %
                    (event.path, new_path))
        except BadSongFile as e:
            self.report_problem_file(event=event, exception=e)
        # probably general error in mmp.magic.move...
        except Exception as e:
            self.unexpected_exception( e )
            self.report_problem_file(event=event, exception=e)
Пример #4
0
 def test_normalized_metadata2(self):
     """
     cc-4305
     """
     orig = Metadata.airtime_dict({
         'date'        : [u'2012-08-27'],
         'tracknumber' : [u'3'],
         'title'       : [u'18-11-00-Untitled Show'],
         'artist'      : [u'Airtime Show Recorder']
     })
     old_path   = "/home/rudi/recorded/doesnt_really_matter.ogg"
     normalized = mmp.normalized_metadata(orig, old_path)
     normalized['MDATA_KEY_BITRATE'] = u'256000'
     opath = mmp.organized_path(old_path, "/srv/airtime/stor/",
             normalized)
     # TODO : add a better test than this...
     self.assertTrue( len(opath) > 0 )