Пример #1
0
    def process_movie(self, info, filepath):

        print info
        print filepath

        title = info['title']

        has_year = False
        if 'year' in info:
            year = info['year']
            has_year = True

        container = info['container']

        # Copy it to its new location
        # Write some info about it into the db
        if has_year:
            display_name = "%s (%s)" % (info['title'], info['year'])
        else:
            display_name = "%s" % info['title']

        final_path = os.path.join(settings.MOVIES_ROOT, display_name)
        if not os.path.exists(final_path):
            os.makedirs(final_path)

        if has_year:
            filename = "%s (%s).%s" % (info['title'], info['year'], info['container'])
        else:
            filename = "%s.%s" % (info['title'], info['container'])

        final_filename = os.path.join(final_path, filename)

        if os.path.exists(final_filename):
            os.unlink(final_filename)

        shutil.move(filepath, final_filename)

        item_name_slug = slugify(display_name)

        # Update db
        try:
            item = MediaItem.objects.get(short_name=item_name_slug)
        except MediaItem.DoesNotExist:
            item = MediaItem(
                media_type=MediaItem.MEDIA_TYPE_MOVIE,
                info_status=MediaItem.INFO_STATUS_NONE,
                display_name=display_name,
                short_name=item_name_slug
            )

            item.media_filename.name = final_filename
            item.save()

        self.stdout.write('Moved file: "%s" -> %s.\n' % (display_name, final_filename))
Пример #2
0
    def process_show(self, info, filepath):

        # print info
        # print filepath

        season_number = int(info['season'])
        series_name = info['series']
        season_name = "Season %s" % season_number

        if 'episodeList' in info:
            episode_list = info['episodeList']
        else:
            episode_list = [info['episodeNumber']]

        episode_long_list = ["%02d" % int(episode) for episode in episode_list]
        episodes = "+".join(episode_long_list)

        display_name = "%s - %d x %s" % (series_name, season_number, episodes)
        final_path = os.path.join(settings.TVSHOWS_ROOT, series_name, season_name)
        if not os.path.exists(final_path):
            os.makedirs(final_path)

        filename = "%s - %d x %s.%s" % (series_name, season_number, episodes, info['container'])
        final_filename = os.path.join(final_path, filename)

        if os.path.exists(final_filename):
            os.unlink(final_filename)

        shutil.move(filepath, final_filename)
        series_name_slug = slugify(series_name)

        try:
            series_group = MediaGroup.objects.get(short_name=series_name_slug)
        except MediaGroup.DoesNotExist:
            series_group = MediaGroup(
                group_type=MediaGroup.GROUP_TYPE_TVSHOW,
                display_name=series_name,
                short_name=series_name_slug
            )
            series_group.save()

        # Update db
        item_name_slug = slugify(display_name)

        try:
            item = MediaItem.objects.get(short_name=item_name_slug)
        except MediaItem.DoesNotExist:
            item = MediaItem(
                media_type=MediaItem.MEDIA_TYPE_TVSHOW,
                info_status=MediaItem.INFO_STATUS_NONE,
                group=series_group,
                display_name=display_name,
                short_name=item_name_slug,
                episode_numbers=episode_list,
                season_number=season_number,
            )

            item.media_filename.name = final_filename
            item.save()

        self.stdout.write('Moved file: "%s" -> %s.\n' % (display_name, final_filename))