Ejemplo n.º 1
0
def create_file(content, filename, *args, **kwargs):
    """
    Create the file and folder structure: filename=.strm file, content= content of file.
    *args = folders to create.
    """

    # Validify and build path
    path = kwargs.get('basedir', '').replace('\\', '/')  # Convert MS-DOS style paths to UNIX style
    if not path:  # Make sure we actually have a basedir
        return
    for folder in args:
        folder = validify_filename(folder)
        path = '{}{}/'.format(path, folder)

    # Validify content of file
    if kwargs.get('clean_url', True):
        content = clean_content(content)
    if not content:
        return
    if not filename:
        return

    # Check that we can actually make the path
    if not make_path(path, warn_dialog=True):
        return

    # Write out our file
    filepath = '{}{}.{}'.format(path, validify_filename(filename), kwargs.get('file_ext', 'strm'))
    write_to_file(filepath, content)
    kodi_log(['ADD LIBRARY -- Successfully added:\n', filepath, '\n', content], 2)
    return filepath
Ejemplo n.º 2
0
def log_request(**kwargs):
    with busy_dialog():
        kwargs['response'] = None
        if not kwargs.get('url'):
            kwargs['url'] = xbmcgui.Dialog().input('URL')
        if not kwargs['url']:
            return
        if kwargs.get('log_request').lower() == 'trakt':
            kwargs['response'] = TraktAPI().get_response_json(kwargs['url'])
        else:
            kwargs['response'] = TMDb().get_response_json(kwargs['url'])
        if not kwargs['response']:
            xbmcgui.Dialog().ok(kwargs['log_request'].capitalize(),
                                u'{}\nNo Response!'.format(kwargs['url']))
            return
        filename = validify_filename(u'{}_{}.json'.format(
            kwargs['log_request'], kwargs['url']))
        dumps_to_file(kwargs, 'log_request', filename)
        xbmcgui.Dialog().ok(
            kwargs['log_request'].capitalize(),
            u'[B]{}[/B]\n\n{}\n{}\n{}'.format(
                kwargs['url'],
                xbmc.translatePath('special://profile/addon_data/'),
                'plugin.video.themoviedb.helper/log_request', filename))
        xbmcgui.Dialog().textviewer(filename,
                                    dumps(kwargs['response'], indent=2))
    def _legacy_conversion(self, folder, tmdb_id):
        # Get details
        details = TMDb().get_request_sc('tv', tmdb_id, append_to_response='external_ids')
        if not details or not details.get('first_air_date'):
            return  # Skip shows without details/year

        # Get new name and compare to old name
        name = u'{} ({})'.format(details.get('name'), details['first_air_date'][:4])
        if folder == name:
            return  # Skip if already converted

        # Convert name
        basedir = BASEDIR_TV.replace('\\', '/')
        old_folder = u'{}{}/'.format(basedir, validify_filename(folder))
        new_folder = u'{}{}/'.format(basedir, validify_filename(name))
        xbmcvfs.rename(old_folder, new_folder)
Ejemplo n.º 4
0
    def _add_episode(self, episode, season, folder):
        number = episode.get('episode_number')
        filename = validify_filename(u'S{:02d}E{:02d} - {}'.format(
            try_int(season), try_int(number), episode.get('name')))
        self.tv._cache.my_history['episodes'].append(filename)

        # Skip episodes we added in the past
        if self._log._add('tv',
                          self.tv.tmdb_id,
                          self.tv._cache.is_added_episode(filename),
                          season=season,
                          episode=number):
            return

        # Skip future episodes
        if self.hide_unaired and is_future_timestamp(episode.get('air_date'),
                                                     "%Y-%m-%d", 10):
            self.tv._cache.my_history['skipped'].append(filename)
            self._log._add('tv',
                           self.tv.tmdb_id,
                           'unaired episode',
                           season=season,
                           episode=number,
                           air_date=episode.get('air_date'))
            return

        # Check if item has already been added
        file = self.tv.get_episode_db_info(season, number, info='file')
        if file:
            self._log._add('tv',
                           self.tv.tmdb_id,
                           'found in library',
                           season=season,
                           episode=number,
                           path=file)
            return

        # Add our strm file
        file = create_file(STRM_EPISODE.format(self.tv.tmdb_id, season,
                                               number),
                           filename,
                           self.tv.name,
                           folder,
                           basedir=BASEDIR_TV)
        self._log._add('tv',
                       self.tv.tmdb_id,
                       'added strm file',
                       season=season,
                       episode=number,
                       path=file)