Beispiel #1
0
    def new_video_from_orphan(self,
                              orphan,
                              target_host=None,
                              delete_orphan=False):
        """
        1. Figures out where to put file based on orphan's title and subtitle -
            creates appropriate subdirectory under target host's top-level
            video directory, if that subdirectory doesn't already exist.
        2. Copies orphan's file to destination subdirectory
        3. Calls activate_video()
        4. If all above was successful and delete_orphan == True, delete the
            orphan's disk file and the Orphan ORM instance.
        """
        # Step 1: Derive source and target. Create target directory, if needed.
        api = MythApi()
        if target_host is None:
            target_host = api.server_name
        if target_host != socket.gethostname():
            raise Exception(
                "Sorry - cross-host file moves not yet implemented.")

        if orphan.title is None or orphan.title == '':
            raise Exception(
                "You must supply a title for the orphaned recording.")
        target_top_level_dir = api.videos_directory
        target_subdir = orphan.title.replace(' ', '_')
        source_dir = api.default_directory
        source_filespec = os.path.join(source_dir, orphan.filename)
        target_directory = os.path.join(target_top_level_dir, target_subdir)
        os.makedirs(target_directory, exist_ok=True)
        # Step 2: Copy file
        shutil.copy2(source_filespec, target_directory, follow_symlinks=True)
        # Step 3: Call MythTV API to add video
        # Construct data dict to pass to activate_video:
        target_filepath = os.path.join(target_subdir, orphan.filename)
        data = {
            'filespec': target_filepath,
            'hostname': target_host,
            'title': orphan.title,
            'subtitle': orphan.subtitle,
            'releasedate': orphan.start_date,
            'length': orphan.duration,  # this value is an integer, in minutes
        }
        v = self.activate_video(data)
        # Step 6: Delete orphan, if desired, but only if activation went OK
        if delete_orphan and v is not None:
            os.remove(source_filespec)
            orphan.delete()
        return v
Beispiel #2
0
 def __init__(self):
     self.api = MythApi()