示例#1
0
def search_generate(what, imdb, settings):

	count = 0
	session = create_session(settings)

	if settings.movies_save:
		url = make_search_url(what, '227,954')
		result1 = search_results(imdb, session, settings, url)
		with filesystem.save_make_chdir_context(settings.movies_path()):
			count += make_search_strms(result1, settings, 'movie')

	if settings.animation_save:
		url = make_search_url(what, '661')
		result2 = search_results(imdb, session, settings, url)
		with filesystem.save_make_chdir_context(settings.animation_path()):
			count += make_search_strms(result2, settings, 'movie')

	if settings.animation_tvshows_save:
		url = make_search_url(what, '232')
		result3 = search_results(imdb, session, settings, url)
		with filesystem.save_make_chdir_context(settings.animation_tvshow_path()):
			count += make_search_strms(result3, settings, 'tvshow')

	if settings.tvshows_save:
		url = make_search_url(what, '768')
		result4 = search_results(imdb, session, settings, url)
		with filesystem.save_make_chdir_context(settings.tvshow_path()):
			count += make_search_strms(result4, settings, 'tvshow')

	return count
示例#2
0
def search_generate(what, imdb, settings):

    count = 0

    session = requests.session()

    if settings.movies_save:
        url = make_search_url(what, 71, imdb, settings)
        result1 = search_results(imdb, session, settings, url, 71)
        with filesystem.save_make_chdir_context(settings.movies_path()):
            count += make_search_strms(result1, settings, "movie")

    if settings.animation_save:
        url = make_search_url(what, 70, imdb, settings)
        result2 = search_results(imdb, session, settings, url, 70)
        with filesystem.save_make_chdir_context(settings.animation_path()):
            count += make_search_strms(result2, settings, "movie")

    if settings.documentary_save:
        url = make_search_url(what, 78, imdb, settings)
        result3 = search_results(imdb, session, settings, url, 78)
        with filesystem.save_make_chdir_context(settings.documentary_path()):
            count += make_search_strms(result3, settings, "movie")

    if settings.tvshows_save:
        url = make_search_url(what, 64, imdb, settings)
        result4 = search_results(imdb, session, settings, url, 64)
        with filesystem.save_make_chdir_context(settings.tvshow_path()):
            count += make_search_strms(result4, settings, "tvshow")

    return count
示例#3
0
def write_tvshow_item(item, path, settings):
	debug('-------------------------------------------------------------------------')
	debug(item.link)
	parser = DescriptionParser(item.link)
	if parser.parsed():
		title = parser.get_value('title')
		debug(title.encode('utf-8'))
		originaltitle = parser.get_value('originaltitle')
		debug(originaltitle.encode('utf-8'))
		season = parser.get_value('season')

		from downloader import TorrentDownloader
		TorrentDownloader(item.link, settings.torrents_path(), settings).download()

		debug('Episodes: ' + str(parser.get_value('episodes')))

		tvshow_path = make_fullpath(title, '')
		debug(tvshow_path.encode('utf-8'))

		with filesystem.save_make_chdir_context(tvshow_path):
			tvshow_api = TVShowAPI(originaltitle, title)
			write_tvshow_nfo(parser, tvshow_api)

		season_path = filesystem.join(make_fullpath(title, u''), u'Season ' + unicode(season))
		debug(season_path.encode('utf-8'))

		with filesystem.save_make_chdir_context(season_path):

			episodes = tvshow_api.episodes(season)

			if len(episodes) < parser.get_value('episodes'):
				for i in range(len(episodes) + 1, parser.get_value('episodes') + 1):
					episodes.append({
						'title': title,
						'showtitle': title,
						'short': 's%02de%02d' % (season, i),
						'episode': i,
						'season': season
					})

			for episode in episodes:
				title = episode['title']
				shortName = episode['short']
				episodeNumber = episode['episode']

				if episodeNumber <= parser.get_value('episodes'):
					filename = str(episodeNumber) + '. ' + 'episode_' + shortName
					debug(filename.encode('utf-8'))

					ep = tvshow_api.Episode(season, episodeNumber)
					if ep:
						episode = ep

					STRMWriter(item.link).write(filename, episodeNumber=episodeNumber, settings=settings)
					NFOWriter(parser, tvshow_api=tvshow_api).write_episode(episode, filename)

	else:
		skipped(item)
	del parser
示例#4
0
def write_episode(info, parser, fulltitle, description, link, settings):

	path = parser.full_tvshow_path
	season_path = 'Season ' + str(info['season'])

	with filesystem.save_make_chdir_context(filesystem.join(path, season_path)):
		from nfowriter import NFOWriter
		filename = '%02d. episode_s%02de%02d' % (info['episode'], info['season'], info['episode'])		

		episode = parser.tvshow_api.Episode(info['season'], info['episode'])
		if not episode:
			episode = {
				'title': info['episode_name'],
				'seasonNumber': info['season'],
				'episodeNumber': info['episode'],
				'image': '',
				'airDate': ''
						}

		NFOWriter(parser, tvshow_api=parser.tvshow_api, movie_api=parser.movie_api()).write_episode(episode, filename)
		from strmwriter import STRMWriter
	
		import re
		link = re.sub(r'/dl/[\d\w]+/', '/dl/', link)

		from downloader import TorrentDownloader
		dl = TorrentDownloader(link, settings.torrents_path(), settings)
		dl.download()

		path = filesystem.join(settings.torrents_path(), dl.get_subdir_name(),
							   dl.get_post_index() + '.torrent')

		STRMWriter(link).write(filename, settings=settings, parser=EpParser(parser, info, path, episode))
示例#5
0
def write_movies_rss(rss_url, path, settings):

	debug('------------------------- Rutor Club: %s -------------------------' % rss_url)

	with filesystem.save_make_chdir_context(path):
		d = feedparser.parse(real_url(rss_url, settings))

		cnt = 0
		settings.progress_dialog.update(0, title(rss_url), path)

		for item in d.entries:
			if is_tvshow(item.title):
				continue

			try:
				debug(item.title.encode('utf-8'))
			except:
				continue
			write_movie_rss(
				fulltitle=item.title,
				description=item.description,
				link=origin_url(get_source_url(item.link), settings),
				settings=settings)

			cnt += 1
			settings.progress_dialog.update(cnt * 100 / len(d.entries), title(rss_url), path)
示例#6
0
    def process_movie(self, url, parser):
        import movieapi
        import filesystem

        api = parser.movie_api()
        genre = api['genres']
        if u'мультфильм' in genre:
            if not self.settings.animation_save:
                return
            base_path = self.settings.animation_path()
        elif u'документальный' in genre:
            if not self.settings.documentary_save:
                return
            base_path = self.settings.documentary_path()
        elif u'клипы' in genre:
            if not self.settings.concert_save:
                return
            base_path = self.settings.concert_path()
        else:
            if not self.settings.movies_save:
                return
            base_path = self.settings.movies_path()

        with filesystem.save_make_chdir_context(base_path, 'kinohd_movies'):
            return movieapi.write_movie(parser.get_value('full_title'),
                                        url,
                                        self.settings,
                                        parser,
                                        path=base_path)
def write_movies_rss(rss_url, path, settings):

    debug('------------------------- NNM Club: %s -------------------------' %
          rss_url)

    with filesystem.save_make_chdir_context(path):
        r = settings.session.get(rss_url)
        if not r.ok:
            return

        d = feedparser.parse(r.content)

        cnt = 0
        settings.progress_dialog.update(0, title(rss_url), path)

        for item in d.entries:
            try:
                debug(item.title.encode('utf-8'))
                write_movie_rss(fulltitle=item.title,
                                description=item.description,
                                link=origin_url(item.link),
                                settings=settings,
                                path=path)
            except:
                continue

            cnt += 1
            settings.progress_dialog.update(cnt * 100 / len(d.entries),
                                            title(rss_url), path)
def write_pages(url,
                path,
                settings,
                params={},
                filter_fn=None,
                dialog_title=None,
                path_out=[]):
    s = get_session(settings)
    if params:
        page = s.post(url, data=params)
    else:
        page = s.get(url)
    soup = BeautifulSoup(page.content, 'html.parser')
    page_no = 1

    cnt = 0

    class Item:
        def __init__(self, link, title):
            self.link = link
            self.title = title

    with filesystem.save_make_chdir_context(path):
        while True:
            if params:
                selector = soup.select('div.search_post > div.text > h2 > a')
            else:
                selector = soup.select(
                    'article.story > div.story_h > div.lcol > h2 > a')

            if not selector:
                break

            settings.progress_dialog.update(0, dialog_title, path)

            for a in selector:
                log.debug(a['href'])
                link = a['href']
                title = a.get_text()
                if filter_fn and filter_fn(title):
                    continue

                write_tvshow_item(Item(link, title), path, settings, path_out)

                cnt += 1
                settings.progress_dialog.update(cnt * 100 / len(selector),
                                                dialog_title, path)

            if not 'favorites' in url:
                break

            page_no += 1
            page = s.get(url + 'page/%d/' % page_no)

            if page.status_code == requests.codes.ok:
                soup = BeautifulSoup(page.text, 'html.parser')
            else:
                break

    return cnt
	def clean_movie_by_imdbid(imdbid):
		api = movieapi.MovieAPI(imdbid)
		genre = api['genres']
		if u'мультфильм' in genre:
			base_path = settings.animation_path()
		elif u'документальный' in genre:
			base_path = settings.documentary_path()
		else:
			base_path = settings.movies_path()

		mm = MoreRequests().get_movies_by_imdb(imdbid)

		from base import STRMWriterBase
		from base import Informer

		title = Informer().filename_with(api['title'], api['originaltitle'], api['year'])

		strm_path = filesystem.join(base_path, make_fullpath(title, '.strm'))
		#alt_path = strm_path + '.alternative'
		nfo_path = filesystem.join(base_path, make_fullpath(title, '.nfo'))

		strm_data = filesystem.fopen(mm[0][3], 'r').read()
		alt_data = []
		for m in mm:
			links_with_ranks = STRMWriterBase.get_links_with_ranks(mm[0][3], settings, use_scrape_info=False)
			alt_data.extend(links_with_ranks)

		alt_data = [dict(t) for t in set([tuple(d.iteritems()) for d in alt_data])]
		#alt_data = list(set(alt_data))
		#alt_data.sort(key=operator.itemgetter('rank'))
		with filesystem.save_make_chdir_context(base_path, 'STRMWriterBase.write_alternative'):
			STRMWriterBase.write_alternative(strm_path, alt_data)
		pass
示例#10
0
def write_movies_rss(rss_url, path, settings):

    debug('------------------------- Rutor: %s -------------------------' %
          rss_url)

    with filesystem.save_make_chdir_context(path):
        d = feedparser.parse(real_url(rss_url, settings))

        cnt = 0
        settings.progress_dialog.update(0, title(rss_url), path)

        for item in d.entries:
            if is_tvshow(item.title):
                continue

            try:
                debug(item.title.encode('utf-8'))
            except:
                continue
            write_movie_rss(fulltitle=item.title,
                            description=item.description,
                            link=origin_url(get_source_url(item.link),
                                            settings),
                            settings=settings,
                            path=path)

            cnt += 1
            settings.progress_dialog.update(cnt * 100 / len(d.entries),
                                            title(rss_url), path)
示例#11
0
def write_favorites(path, settings):
	s = get_session(settings)
	page = s.get('http://tr.anidub.com/favorites/')
	soup = BeautifulSoup(page.text, 'html.parser')
	page_no = 1

	class Item:
		def __init__(self, link, title):
			self.link = link
			self.title = title

	with filesystem.save_make_chdir_context(path):
		while True:
			selector = soup.select('article.story > div.story_h > div.lcol > h2 > a')
			if not selector:
				break

			cnt = 0
			settings.progress_dialog.update(0, 'anidub favorites', path)

			for a in selector:
				log.debug(a['href'])
				link = a['href']
				title = a.get_text()
				write_tvshow_item(Item(link, title), path, settings)

				cnt += 1
				settings.progress_dialog.update(cnt * 100 / len(selector), 'anidub favorites', path)

			page_no += 1
			page = s.get('http://tr.anidub.com/favorites/page/%d/' % page_no)

			if page.status_code == requests.codes.ok:
				soup = BeautifulSoup(page.text, 'html.parser')
示例#12
0
def write_twshow(info, settings):
	parser = DescriptionParser(info, settings)

	with filesystem.save_make_chdir_context(parser.full_tvshow_path):
		from nfowriter import NFOWriter
		NFOWriter(parser, tvshow_api=parser.tvshow_api, movie_api=parser.movie_api()).write_tvshow_nfo()

	return parser
示例#13
0
def search_generate(what, imdb, settings, path_out):

    count = 0
    session = create_session(settings)

    if settings.movies_save:
        url = make_search_url(what, movie_ids)
        result1 = search_results(imdb, session, settings, url)
        count += make_search_strms(result1, settings, 'movie',
                                   settings.movies_path(), path_out)

    if settings.animation_save and count == 0:
        url = make_search_url(what, animation_ids)
        result2 = search_results(imdb, session, settings, url)
        count += make_search_strms(result2, settings, 'movie',
                                   settings.animation_path(), path_out)

    if settings.animation_tvshows_save and count == 0:
        url = make_search_url(what, animation_tvshow_ids)
        result3 = search_results(imdb, session, settings, url, 'tvshow')
        count += make_search_strms(result3, settings, 'tvshow',
                                   settings.animation_tvshow_path(), path_out)

    if settings.tvshows_save and count == 0:
        url = make_search_url(what, tvshow_ids)
        result4 = search_results(imdb, session, settings, url, 'tvshow')
        count += make_search_strms(result4, settings, 'tvshow',
                                   settings.tvshow_path(), path_out)

    if settings.documentary_tvshows_save and count == 0:
        url = make_search_url(what, documentary_tvshow_ids)
        result5 = search_results(imdb, session, settings, url)
        with filesystem.save_make_chdir_context(
                settings.documentary_tvshow_path()):
            count += make_search_strms(result5, settings, 'tvshow', path_out)

    if settings.concert_save and count == 0:
        url = make_search_url(what, concert_ids)
        result6 = search_results(imdb, session, settings, url)
        count += make_search_strms(result6, settings, 'movie',
                                   settings.concert_path(), path_out)

    if settings.kids_save and count == 0:
        url = make_search_url(what, kids_ids)
        result7 = search_results(imdb, session, settings, url)
        count += make_search_strms(result7, settings, 'movie',
                                   settings.kids_path(), path_out)

    if settings.theater_save and count == 0:
        url = make_search_url(what, theater_ids)
        result8 = search_results(imdb, session, settings, url)
        count += make_search_strms(result8, settings, 'movie',
                                   settings.theater_path(), path_out)

    return count
示例#14
0
def write_tvshow(content, path, settings):
	with filesystem.save_make_chdir_context(path):
		d = feedparser.parse(content)

		cnt = 0
		settings.progress_dialog.update(0, 'anidub', path)

		for item in d.entries:
			write_tvshow_item(item, path, settings)

			cnt += 1
			settings.progress_dialog.update(cnt * 100 / len(d.entries), 'anidub', path)
示例#15
0
def write_movies(rss_url, path, settings):
    with filesystem.save_make_chdir_context(path):
        d = feedparser.parse(rss_url)

        cnt = 0
        settings.progress_dialog.update(0, "hdclub", path)

        for item in d.entries:
            write_movie(item, settings)

            cnt += 1
            settings.progress_dialog.update(cnt * 100 / len(d.entries), "hdclub", path)
示例#16
0
def create(settings):

    #import vsdbg
    #vsdbg._bp()

    need_restart = False
    sources = Sources()

    with filesystem.save_make_chdir_context(settings.base_path()):

        if settings.anime_save:
            path = settings.anime_tvshow_path()
            if not filesystem.exists(path):
                filesystem.makedirs(path)
            sources.add_video(path, u'Аниме', 'tvshows')
            need_restart = True

        if settings.animation_save:
            path = settings.animation_path()
            if not filesystem.exists(path):
                filesystem.makedirs(path)
            sources.add_video(path, u'Мультфильмы', 'movies')
            need_restart = True

        if settings.animation_tvshows_save:
            path = settings.animation_tvshow_path()
            if not filesystem.exists(path):
                filesystem.makedirs(path)
            sources.add_video(path, u'Мультсериалы', 'tvshows')
            need_restart = True

        if settings.tvshows_save:
            path = settings.tvshow_path()
            if not filesystem.exists(path):
                filesystem.makedirs(path)
            sources.add_video(path, u'Сериалы', 'tvshows')
            need_restart = True

        if settings.documentary_save:
            path = settings.documentary_path()
            if not filesystem.exists(path):
                filesystem.makedirs(path)
            sources.add_video(path, u'Документальное', 'movies')
            need_restart = True

        if settings.movies_save:
            path = settings.movies_path()
            if not filesystem.exists(path):
                filesystem.makedirs(path)
            sources.add_video(path, u'Фильмы', 'movies')
            need_restart = True

    return need_restart
示例#17
0
def write_tvshow(content, path, settings):
    with filesystem.save_make_chdir_context(path):
        d = feedparser.parse(content)

        cnt = 0
        settings.progress_dialog.update(0, 'anidub', path)

        for item in d.entries:
            write_tvshow_item(item, path, settings)

            cnt += 1
            settings.progress_dialog.update(cnt * 100 / len(d.entries),
                                            'anidub', path)
示例#18
0
def search_generate(what, imdb, settings, path_out):
    count = 0

    if settings.movies_save:
        url = 'http://rutor.info/search/0/1/010/2/' + imdb
        result1 = search_results(imdb, settings, url)
        count += make_search_strms(result1, settings, 'movie',
                                   settings.movies_path(), path_out)

    if settings.animation_save and count == 0:
        url = 'http://rutor.info/search/0/7/010/2/' + imdb
        result2 = search_results(imdb, settings, url)
        count += make_search_strms(result2, settings, 'movie',
                                   settings.animation_path(), path_out)

    if settings.animation_tvshows_save and count == 0:
        url = 'http://rutor.info/search/0/7/010/2/' + imdb
        result3 = search_results(imdb, settings, url)
        count += make_search_strms(result3, settings, 'tvshow',
                                   settings.animation_tvshow_path(), path_out)

    if settings.tvshows_save and count == 0:
        url = 'http://rutor.info/search/0/4/010/2/' + imdb
        result4 = search_results(imdb, settings, url)
        count += make_search_strms(result4, settings, 'tvshow',
                                   settings.tvshow_path(), path_out)

    if settings.documentary_tvshows_save and count == 0:
        url = 'http://rutor.info/search/0/12/010/2/' + imdb
        result5 = search_results(imdb, settings, url)
        with filesystem.save_make_chdir_context(
                settings.documentary_tvshow_path()):
            count += make_search_strms(result5, settings, 'tvshow', path_out)

    if settings.movies_save and count == 0:
        # 0/5/000/0 - Наше кино, поиск по названию в разделе
        if not result1:
            url = 'http://rutor.info/search/0/5/000/0/' + urllib2.quote(
                what.encode('utf-8'))
            result1 = search_results(None, settings, url, what)
            count += make_search_strms(result1, settings, 'movie',
                                       settings.movies_path(), path_out)
    """
		if not result4:
			url = 'http://rutor.info/search/0/4/000/0/' + urllib2.quote(what.encode('utf-8'))
			result4 = search_results(None, settings, url, what)
			with filesystem.save_make_chdir_context(settings.tvshow_path()):
				count += make_search_strms(result4, settings, 'tvshow', path_out)
	"""

    return count
示例#19
0
def write_movies(rss_url, path, settings):
    with filesystem.save_make_chdir_context(path):
        d = feedparser.parse(real_url(rss_url))

        cnt = 0
        settings.progress_dialog.update(0, 'elitehd', path)

        for item in d.entries:
            item.link = origin_url(item.link)
            write_movie(item, settings)

            cnt += 1
            settings.progress_dialog.update(cnt * 100 / len(d.entries),
                                            'elitehd', path)
示例#20
0
def create(settings):
	need_restart = False
	sources = Sources()

	with filesystem.save_make_chdir_context(settings.base_path()):

		if settings.anime_save:
			path = settings.anime_tvshow_path()
			if not filesystem.exists(path):
				filesystem.makedirs(path)
			sources.add_video(path, u'Аниме', 'tvshows')
			need_restart = True

		if settings.animation_save:
			path = settings.animation_path()
			if not filesystem.exists(path):
				filesystem.makedirs(path)
			sources.add_video(path, u'Мультфильмы', 'movies')
			need_restart = True

		if settings.animation_tvshows_save:
			path = settings.animation_tvshow_path()
			if not filesystem.exists(path):
				filesystem.makedirs(path)
			sources.add_video(path, u'Мультсериалы', 'tvshows')
			need_restart = True

		if settings.tvshows_save:
			path = settings.tvshow_path()
			if not filesystem.exists(path):
				filesystem.makedirs(path)
			sources.add_video(path, u'Сериалы', 'tvshows')
			need_restart = True

		if settings.documentary_save:
			path = settings.documentary_path()
			if not filesystem.exists(path):
				filesystem.makedirs(path)
			sources.add_video(path, u'Документальное', 'movies')
			need_restart = True

		if settings.movies_save:
			path = settings.movies_path()
			if not filesystem.exists(path):
				filesystem.makedirs(path)
			sources.add_video(path, u'Фильмы', 'movies')
			need_restart = True

	return need_restart
示例#21
0
def write_movies(content, path, settings, tracker=False):

	with filesystem.save_make_chdir_context(path):
		# ---------------------------------------------
		if tracker:
			_ITEMS_ON_PAGE = 50
			enumerator = TrackerPostsEnumerator()
		else:
			_ITEMS_ON_PAGE = 15
			enumerator = PostsEnumerator()
		for i in range(settings.nnmclub_pages):
			enumerator.process_page(content + _NEXT_PAGE_SUFFIX + str(i * _ITEMS_ON_PAGE))

		for post in enumerator.items():
			write_movie(post, settings, tracker)
示例#22
0
def write_movies(content, path, settings, tracker=False):

    with filesystem.save_make_chdir_context(path):
        # ---------------------------------------------
        if tracker:
            _ITEMS_ON_PAGE = 50
            enumerator = TrackerPostsEnumerator()
        else:
            _ITEMS_ON_PAGE = 15
            enumerator = PostsEnumerator()
        for i in range(settings.nnmclub_pages):
            enumerator.process_page(content + _NEXT_PAGE_SUFFIX +
                                    str(i * _ITEMS_ON_PAGE))

        for post in enumerator.items():
            write_movie(post, settings, tracker)
示例#23
0
def write_tvshows(rss_url, path, settings):

    return  # TODO: Later

    with filesystem.save_make_chdir_context(path):
        d = feedparser.parse(real_url(rss_url))

        cnt = 0
        settings.progress_dialog.update(0, 'bluebird', path)

        for item in d.entries:
            item.link = origin_url(item.link)
            write_tvshow(item, settings)

            cnt += 1
            settings.progress_dialog.update(cnt * 100 / len(d.entries),
                                            'bluebird', path)
示例#24
0
def save_dbs():
    path = filesystem.join(_addondir, 'dbversions')

    with filesystem.save_make_chdir_context(path):

        for fn in filesystem.listdir(path):
            filesystem.remove(fn)

        log_dir = xbmc.translatePath('special://logpath').decode('utf-8')
        log_path = filesystem.join(log_dir, 'kodi.log')
        log.debug(log_path)
        with filesystem.fopen(log_path, 'r') as lf:
            for line in lf.readlines():
                if 'Running database version' in line:
                    log.debug(line)
                    name = line.split(' ')[-1].strip('\r\n\t ').decode('utf-8')
                    with filesystem.fopen(name, 'w'):
                        pass
示例#25
0
def save_dbs():
	path = filesystem.join(_addondir, 'dbversions')

	with filesystem.save_make_chdir_context(path):

		for fn in filesystem.listdir(path):
			filesystem.remove(fn)

		log_dir = xbmc.translatePath('special://logpath').decode('utf-8')
		log_path = filesystem.join(log_dir, 'kodi.log')
		log.debug(log_path)
		with filesystem.fopen(log_path, 'r') as lf:
			for line in lf.readlines():
				if 'Running database version' in line:
					log.debug(line)
					name = line.split(' ')[-1].strip('\r\n\t ').decode('utf-8')
					with filesystem.fopen(name, 'w'):
						pass
示例#26
0
def write_tvshow(fulltitle, link, settings, parser):
	from nfowriter import NFOWriter
	from strmwriter import STRMWriter
	import requests

	from downloader import TorrentDownloader
	dl = TorrentDownloader(parser.link(), settings.torrents_path(), settings)
	if not dl.download():
		return

	#r = requests.get(link)
	#if r.status_code == requests.codes.ok:
	with filesystem.fopen(dl.get_filename(), 'rb') as torr:
		content = torr.read()
		files = parse_torrent(content, season_from_title(fulltitle))

		title = parser.get_value('title')
		debug(title.encode('utf-8'))
		originaltitle = parser.get_value('originaltitle')
		debug(originaltitle.encode('utf-8'))

		imdb_id = parser.get('imdb_id', None)
		kp_id = parser.get('kp_id', None)
		tvshow_api = TVShowAPI(originaltitle, title, imdb_id, kp_id)

		api_title = tvshow_api.Title()
		tvshow_path = make_fullpath(api_title if api_title is not None else title, '')
		debug(tvshow_path.encode('utf-8'))

		if tvshow_path:
			with filesystem.save_make_chdir_context(tvshow_path):

				NFOWriter(parser, tvshow_api=tvshow_api, movie_api=parser.movie_api()).write_tvshow_nfo()

				# cnt = 0
				for f in files:
					# cnt += 1
					s_num = f['season'] if f['season'] else 1
					try:
						episode = tvshow_api.Episode(s_num, f['episode'])
						if not episode:
							episode = {
								'title': title,
								'seasonNumber': s_num,
								'episodeNumber': f['episode'],
								'image': '',
								'airDate': ''
							}

						season_path = 'Season %d' % s_num
					except BaseException as e:
						print_tb(e)
						continue

					with filesystem.save_make_chdir_context(season_path):

						results = filter(lambda x: x['season'] == s_num and x['episode'] == f['episode'], files)
						if len(results) > 1:	# Has duplicate episodes
							filename = f['name']
						else:
							try:
								cnt = f['episode']
								filename = '%02d. episode_s%02de%02d' % (cnt, s_num, f['episode'])
							except BaseException as e:
								print_tb(e)
								filename = f['name']

						try:
							debug(filename)
							filename = filename.decode('utf-8')
						except:
							debug([filename])

						STRMWriter(parser.link()).write(filename, index=f['index'], settings=settings, parser=parser)
						NFOWriter(parser, tvshow_api=tvshow_api, movie_api=parser.movie_api()).write_episode(episode, filename)
示例#27
0
def write_tvshow(fulltitle,
                 link,
                 settings,
                 parser,
                 path,
                 skip_nfo_exists=False):
    from nfowriter import NFOWriter
    from strmwriter import STRMWriter
    import requests

    from downloader import TorrentDownloader
    dl = TorrentDownloader(parser.link(), settings.torrents_path(), settings)
    if not dl.download():
        return None

    #r = requests.get(link)
    #if r.status_code == requests.codes.ok:
    with filesystem.fopen(dl.get_filename(), 'rb') as torr:
        content = torr.read()
        files = parse_torrent(content, season_from_title(fulltitle))

        title = parser.get_value('title')
        debug(title)
        originaltitle = parser.get_value('originaltitle')
        debug(originaltitle)

        imdb_id = parser.get('imdb_id', None)
        kp_id = parser.get('kp_id', None)
        tvshow_api = TVShowAPI.get_by(originaltitle, title, imdb_id, kp_id)

        api_title = parser.movie_api().get('title')
        if not api_title:
            api_title = tvshow_api.Title()
        tvshow_path = make_fullpath(
            api_title if api_title is not None else title, '')
        debug(tvshow_path)

        if tvshow_path:
            tvshow_path = filesystem.join(path, tvshow_path)
            with filesystem.save_make_chdir_context(tvshow_path):

                NFOWriter(
                    parser,
                    tvshow_api=tvshow_api,
                    movie_api=parser.movie_api()).write_tvshow_nfo(tvshow_path)

                # cnt = 0
                for f in files:
                    # cnt += 1
                    s_num = f['season'] if f['season'] else 1
                    try:
                        episode = tvshow_api.Episode(s_num, f['episode'])
                        if not episode:
                            episode = {
                                'title': title,
                                'seasonNumber': s_num,
                                'episodeNumber': f['episode'],
                                'image': '',
                                'airDate': ''
                            }

                        season_path = 'Season %d' % s_num
                    except BaseException as e:
                        print_tb(e)
                        continue

                    season_path = filesystem.join(tvshow_path, season_path)
                    with filesystem.save_make_chdir_context(season_path):

                        results = filter(
                            lambda x: x['season'] == s_num and x['episode'] ==
                            f['episode'], files)
                        if len(results) > 1:  # Has duplicate episodes
                            filename = f['name']
                        else:
                            try:
                                cnt = f['episode']
                                filename = '%02d. episode_s%02de%02d' % (
                                    cnt, s_num, f['episode'])
                            except BaseException as e:
                                print_tb(e)
                                filename = f['name']

                        try:
                            debug(filename)
                            filename = filename.decode('utf-8')
                        except:
                            debug([filename])

                        STRMWriter(parser.link()).write(filename,
                                                        season_path,
                                                        index=f['index'],
                                                        settings=settings,
                                                        parser=parser)
                        NFOWriter(parser,
                                  tvshow_api=tvshow_api,
                                  movie_api=parser.movie_api()).write_episode(
                                      episode,
                                      filename,
                                      season_path,
                                      skip_nfo_exists=skip_nfo_exists)
            return tvshow_path
            # end for
        else:
            return None
示例#28
0
def write_tvshow_item(item, path, settings, path_out=[]):
    debug(
        '-------------------------------------------------------------------------'
    )
    debug(item.link)
    parser = DescriptionParser(item.link)
    if parser.parsed():
        title = parser.get_value('title')
        debug(title.encode('utf-8'))
        originaltitle = parser.get_value('originaltitle')
        debug(originaltitle.encode('utf-8'))
        season = parser.get_value('season')

        from downloader import TorrentDownloader
        TorrentDownloader(item.link, settings.torrents_path(),
                          settings).download()

        debug('Episodes: ' + str(parser.get_value('episodes')))

        tvshow_path = make_fullpath(title, '')

        tvshow_path = filesystem.join(path, tvshow_path)
        debug(tvshow_path)

        path_out.append(tvshow_path)

        with filesystem.save_make_chdir_context(tvshow_path):
            tvshow_api = TVShowAPI.get_by(originaltitle, title)
            write_tvshow_nfo(parser, tvshow_api, tvshow_path)

        season_path = filesystem.join(tvshow_path,
                                      u'Season ' + unicode(season))
        debug(season_path.encode('utf-8'))

        with filesystem.save_make_chdir_context(season_path):

            episodes = tvshow_api.episodes(season)

            if len(episodes) < parser.get_value('episodes'):
                for i in range(
                        len(episodes) + 1,
                        parser.get_value('episodes') + 1):
                    episodes.append({
                        'title': title,
                        'showtitle': title,
                        'short': 's%02de%02d' % (season, i),
                        'episode': i,
                        'season': season
                    })

            for episode in episodes:
                title = episode['title']
                shortName = episode['short']
                episodeNumber = episode['episode']

                if episodeNumber <= parser.get_value('episodes'):
                    filename = str(
                        episodeNumber) + '. ' + 'episode_' + shortName
                    debug(filename)

                    ep = tvshow_api.Episode(season, episodeNumber)
                    if ep:
                        episode = ep

                    STRMWriter(item.link).write(filename,
                                                season_path,
                                                episodeNumber=episodeNumber,
                                                settings=settings)
                    NFOWriter(parser, tvshow_api=tvshow_api).write_episode(
                        episode, filename, season_path)

    else:
        skipped(item)
    del parser