コード例 #1
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
コード例 #2
0
def write_movie(item, settings):
    full_title = item.title
    debug('full_title: ' + full_title.encode('utf-8'))

    parser = DescriptionParser(full_title, item.description, item.link,
                               settings)
    debug(
        '-------------------------------------------------------------------------'
    )

    if parser.need_skipped(full_title):
        return

    if parser.parsed():
        filename = parser.make_filename()
        if not filename:
            return

        debug('filename: ' + filename.encode('utf-8'))
        STRMWriter(origin_url(item.link)).write(filename,
                                                parser=parser,
                                                settings=settings)
        NFOWriter(parser, movie_api=parser.movie_api()).write_movie(filename)
        from downloader import TorrentDownloader
        TorrentDownloader(item.link, settings.torrents_path(),
                          settings).download()
    else:
        skipped(item)

    del parser
コード例 #3
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))
コード例 #4
0
ファイル: base.py プロジェクト: ssmol/script.media.aggregator
def is_torrent_remembed(parser, settings):
    from downloader import TorrentDownloader
    import urllib
    link = parser.get('link').split('torrent=')[-1]
    if link:
        torr_downloader = TorrentDownloader(urllib.unquote(link), None,
                                            settings)
        path = filesystem.join(settings.torrents_path(),
                               torr_downloader.get_subdir_name(),
                               torr_downloader.get_post_index() + '.choice')
        return filesystem.exists(path)

    return False
コード例 #5
0
def get_path_or_url_and_episode(settings, params, torrent_source):
	tempPath = xbmc.translatePath('special://temp').decode('utf-8')
	
	from downloader import TorrentDownloader
	torr_downloader = TorrentDownloader(urllib.unquote(torrent_source), tempPath, settings)

	path = filesystem.join(settings.torrents_path(), torr_downloader.get_subdir_name(),
	                       torr_downloader.get_post_index() + '.torrent')
	if not filesystem.exists(path):
		if not torr_downloader.start():
			return None
		torr_downloader.move_file_to(path)
		torr_downloader = None

	return {'path_or_url': path, 'episode': params.get('episodeNumber', None), 'downloader': torr_downloader}
コード例 #6
0
	def download_torrent(self, link):
		tempPath = xbmc.translatePath('special://temp').decode('utf-8')
		from downloader import TorrentDownloader
		import player
		settings = self.settings
		import urllib
		torr_downloader = TorrentDownloader(urllib.unquote(link), tempPath, settings)
		path = filesystem.join(settings.torrents_path(), torr_downloader.get_subdir_name(), torr_downloader.get_post_index() + '.torrent')
		if not filesystem.exists(path):
			torr_downloader.download()
			path = torr_downloader.get_filename()

		debug(path)

		return path
コード例 #7
0
    def show_menu(self):
        if self.left_menu:
            return

        self.left_menu = pyxbmct.List('font14')
        self.placeControl(self.left_menu, 0, 0)

        link = self.cursel_link()

        self.list.setVisible(False)

        #path = self.download_torrent(link)
        #choice_path = path.replace('.torrent', '.choice')
        from downloader import TorrentDownloader
        import urllib
        torr_downloader = TorrentDownloader(urllib.unquote(link), None,
                                            self.settings)
        choice_path = filesystem.join(
            self.settings.torrents_path(), torr_downloader.get_subdir_name(),
            torr_downloader.get_post_index() + '.choice')

        # +++

        if self.settings.copy_torrent_path:
            li = xbmcgui.ListItem(u'Копировать торрент')
            li.setProperty('link', link)
            #li.setProperty('path', path)
            li.setProperty('action', 'copy_torrent')
            self.left_menu.addItem(li)

        if filesystem.exists(choice_path):
            li = xbmcgui.ListItem(u'Отменить выбор')
            li.setProperty('link', link)
            li.setProperty('path', choice_path)
            li.setProperty('action', 'cancel_choice')
        else:
            li = xbmcgui.ListItem(u'Запомнить выбор')
            li.setProperty('link', link)
            li.setProperty('path', choice_path)
            li.setProperty('action', 'remember_choice')
        self.left_menu.addItem(li)

        # +++

        self.setFocus(self.left_menu)
        self.connect(self.left_menu, self.select_menu_item)
コード例 #8
0
def write_movie(post, settings, tracker):
    debug('!-------------------------------------------')
    parser = DescriptionParser(post, settings=settings, tracker=tracker)
    if parser.parsed():
        debug('+-------------------------------------------')
        full_title = parser.get_value('full_title')
        filename = parser.make_filename()
        if filename:
            debug('full_title: ' + full_title.encode('utf-8'))
            debug('filename: ' + filename.encode('utf-8'))
            debug('-------------------------------------------+')
            STRMWriter(parser.link()).write(filename,
                                            parser=parser,
                                            settings=settings)
            NFOWriter(parser,
                      movie_api=parser.movie_api()).write_movie(filename)

            link = None
            try:
                link = post.select('a[href*="download.php"]')[0]['href']
            except:
                try:
                    link = post.find_parent('tr').select(
                        'a[href*="download.php"]')[0]['href']
                except:
                    pass
            #if link:
            #	save_download_link(parser, settings, 'http://nnm-club.me/forum/' + link + '&uk=' + settings.nnmclub_passkey)

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

        # time.sleep(1)

    del parser
コード例 #9
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
コード例 #10
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