Ejemplo n.º 1
0
    def podcast_create(self, archive_type, broadcast_id, podcast_name, max_allowed=None,
                       remove_commercials=False, file_location=None, artist_name=None,
                       automatic_download=True):
        '''
        Create new podcast
        archive_type         :   Where podcast is downloaded from (rss/soundcloud/youtube)
        broadcast_id         :   Identifier of podcast by archive_type, such as youtube channel ID
        podcast_name         :   Name to identify podcast in database
        max_allowed          :   When syncing the podcast, keep the last N episodes(if none keep all)
        remove_commercials   :   Attempt to remove commercials once audio files are downloaded
        file_location        :   Where podcast files will be stored
        artist_name          :   Name of artist to use when updating media file metadata
        automatic_download   :   Automatically download new episodes with file-sync

        Returns: Integer ID of created podcast
        '''
        self._check_argument_type(podcast_name, basestring, 'Podcast name must be string type')
        self._check_argument_type(broadcast_id, basestring, 'Brodcast ID must be string type')
        self._check_argument_type(archive_type, basestring, 'Archive Type must be string type')
        self._check_argument_type(automatic_download, bool, 'Automatic download must be boolean type')
        self._check_argument_type(remove_commercials, bool, 'Remove commercials must be boolean type')
        self._check_argument_type(max_allowed, [None, int], 'Max allowed must be None or int type')
        self._check_argument_type(file_location, [None, basestring], 'File location must be None or string type')
        self._check_argument_type(artist_name, [None, basestring], 'File location must be None or string type')

        self._check_argument_oneof(archive_type, ARCHIVE_KEYS, 'Archive Type must be in accepted list of keys')

        if max_allowed is not None and max_allowed < 1:
            self._fail('Max allowed must be positive integer, %s given' % max_allowed)

        if file_location is None:
            if self.podcast_directory is None:
                self._fail("No default podcast directory specified, will need specific file location to create podcast")
            file_location = os.path.join(self.podcast_directory, utils.normalize_name(podcast_name))

        pod_args = {
            'name' : utils.clean_string(podcast_name),
            'archive_type' : archive_type,
            'broadcast_id' : utils.clean_string(broadcast_id),
            'max_allowed' : max_allowed,
            'remove_commercial' : remove_commercials,
            'file_location' : os.path.abspath(file_location),
            'artist_name' : utils.clean_string(artist_name),
            'automatic_episode_download' : automatic_download,
        }
        new_pod = Podcast(**pod_args)
        try:
            self.db_session.add(new_pod)
            self.db_session.commit()
            self.logger.info("Podcast created in database, id:%d, args %s",
                             new_pod.id, ' -- '.join('%s-%s' % (k, v) for k, v in pod_args.items()))
        except IntegrityError:
            self.db_session.rollback()
            self._fail('Cannot create podcast, name was %s' % pod_args['name'])

        self.logger.debug("Ensuring podcast %d path exists %s", new_pod.id, file_location)
        self._ensure_path(file_location)
        return new_pod.id
Ejemplo n.º 2
0
 def test_normalize_name(self):
     self.assertEqual('a_b', utils.normalize_name('a______b'))
     self.assertEqual('a_b', utils.normalize_name('a&-b'))
Ejemplo n.º 3
0
 def build_episode_path(episode, podcast):
     pod_path = podcast['file_location']
     title = utils.normalize_name(episode.title)
     date = utils.normalize_name(episode.date.strftime(self.datetime_output_format))
     file_name = '%s.%s' % (date, title)
     return os.path.join(pod_path, file_name)