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
Exemplo n.º 2
0
def write_movie(fulltitle,
                link,
                settings,
                parser,
                path,
                skip_nfo_exists=False,
                download_torrent=True):
    debug('+-------------------------------------------')
    filename = parser.make_filename()
    if filename:
        debug('fulltitle: ' + fulltitle.encode('utf-8'))
        debug('filename: ' + filename.encode('utf-8'))
        debug('-------------------------------------------+')
        from strmwriter import STRMWriter
        STRMWriter(parser.link()).write(filename,
                                        path,
                                        parser=parser,
                                        settings=settings)
        from nfowriter import NFOWriter
        NFOWriter(parser, movie_api=parser.movie_api()).write_movie(
            filename, path, skip_nfo_exists=skip_nfo_exists)

        if download_torrent:
            from downloader import TorrentDownloader
            TorrentDownloader(parser.link(), settings.torrents_path(),
                              settings).download()

        return filesystem.relpath(filesystem.join(
            path, base.make_fullpath(filename, '.strm')),
                                  start=settings.base_path())
    else:
        return None
Exemplo n.º 3
0
    def parse(self):
        a = None
        if self.tracker:
            a = self.content
        else:
            for __a in self.content.select('.substr a.pgenmed'):
                a = __a
                break

        if a != None:
            try:
                self._link = origin_url(_BASE_URL + a['href'])
                debug(self._link)
            except:
                # debug(a.__repr__())
                return False

            full_title = a.get_text().strip(' \t\n\r')
            debug('full_title: ' + full_title.encode('utf-8'))

            self.parse_title(full_title)

            if self.need_skipped(full_title):
                return False

            fname = base.make_fullpath(self.make_filename(), '.strm')
            if base.STRMWriterBase.has_link(fname, self._link):
                debug('Already exists')
                return False

            r = self.settings.session.get(self._link)
            if r.status_code == requests.codes.ok:
                return self.parse_description(r.text)

        return False
Exemplo n.º 4
0
	def parse(self):
		a = None
		if self.tracker:
			a = self.content
		else:
			for __a in self.content.select('.substr a.pgenmed'):
				a = __a
				break

		if a != None:
			try:
				self._link = origin_url(_BASE_URL + a['href'])
				debug(self._link)
			except:
				# debug(a.__repr__())
				return False

			full_title = a.get_text().strip(' \t\n\r')
			debug('full_title: ' + full_title.encode('utf-8'))

			self.parse_title(full_title)

			if self.need_skipped(full_title):
				return False

			fname = base.make_fullpath(self.make_filename(), '.strm')
			if base.STRMWriterBase.has_link(fname, self._link):
				debug('Already exists')
				return False

			r = requests.get(real_url(self._link))
			if r.status_code == requests.codes.ok:
				return self.parse_description(r.text)

		return False
Exemplo n.º 5
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
Exemplo n.º 6
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)
Exemplo n.º 7
0
	def tvshow_path(self):
		api_title = self.tvshow_api.Title()
		return make_fullpath(api_title if api_title is not None else self.api_info['title_ru'], '')