Esempio n. 1
0
    def set_rating(self, rating):
        assert isinstance(rating, (int, str))
        if isinstance(rating, str):
            self._rating_code = get_content_rating(rating)
        else:
            self._rating_code = rating

        self._rating = get_content_rating_name(self._rating_code)
def main():
    if not os.path.isdir('logs'):
        os.mkdir('logs')

    config_file = os.path.join('logs', 'config.cfg')
    config = config_load(config_file, no_save=True)

    conn = PlexServerConnection(
        config['plex_server_host'], config['plex_server_port'])

    sections_page = conn.fetch('library/sections')
    sections_soup = BeautifulSoup(sections_page)

    for section_tag in sections_soup.find_all('directory'):
        key = section_tag['key']

        print('{0:#^40}'.format("[ " + section_tag['title'] + " ]"))
        items_page = conn.fetch('library/sections/{0}/all'.format(key))
        items_soup = BeautifulSoup(items_page)

        ratings = [[] for i in range(RATING_UNKNOWN + 1)]

        for item in itertools.chain(
                items_soup.find_all('directory'),
                items_soup.find_all('video')):
            string_rating = item.get('contentrating', '')

            content_rating = get_content_rating(string_rating)
            ratings[content_rating].append(item.get('title'))

        for rating, shows in enumerate(ratings):
            if len(shows) == 0:
                continue
            print(u"  {0}".format(get_content_rating_name(rating)))
            for show in shows:
                print(u"    {0}".format(show))
            print('')
Esempio n. 3
0
    def _parse_xml(self, xml, soup=None):
        if soup is None:
            soup = BeautifulSoup(xml)
        super(PlexMediaVideoObject, self)._parse_xml(xml, soup)
        video_tag = soup.find('video', ratingkey=str(self.key))

        self.rating      = video_tag.get('contentrating', '')
        self.rating_code = get_content_rating(self.rating)

        self.duration    = int(video_tag.get('duration', 0))
        self.year        = video_tag.get('year', '1900')
        self.title       = video_tag.get('title', '')
        self.summary     = video_tag.get('summary', '')

        self.added_at    = datetime.datetime.fromtimestamp(
            float(video_tag.get('addedat', 0)))
        self.aired_at    = datetime.datetime(*map(
            int,
            video_tag.get('originallyavailableat', '1900-1-1').split('-')))

        ## TODO: Make this better, but I haven't really needed this yet,
        ## so I haven't decided how it needs to be laid out.
        media_tags = video_tag.find_all('media', id=True)
        for media_tag in media_tags:
            media_id = media_tag['id']
            self.media[media_id] = []
            part_tags = media_tag.find_all('part', id=True)
            for part_tag in part_tags:
                part_id = part_tag['id']
                part = {'id': part_id}
                if part_tag.has_attr('file'):
                    part['file'] = part_tag['file']
                if part_tag.has_attr('key'):
                    part['key'] = part_tag['key']
                self.media[media_id].append(part)
                self.parts.append(part_id)