Ejemplo n.º 1
0
	def __init__(self, parser, info, torr_path, episode):
		self._dict = dict(parser.Dict())
		parts = []

		parts.append('AVC/H.264')

		if info['quality'].lower() == 'sd':
			parts.append('720x540')
		elif info['quality'].lower() == 'hd':
			parts.append('1280x720')
		elif info['quality'].lower() == 'fullhd':
			parts.append('1920x1080')

		from base import TorrentPlayer
		player = TorrentPlayer()
		player.AddTorrent(torr_path)
		data = player.GetLastTorrentData()
		if data:
			add_dict = self.get_add_data(data)
			if episode:
				seconds = int(parser.episode_runtime) * 60
				bitrate = add_dict['size'] * 8 / seconds
				parts.append(str(bitrate / 1000) + ' kbs')

		if parts:
			self._dict['video'] = ', '.join(parts)
Ejemplo n.º 2
0
	def __init__(self, settings):
		self.settings = settings
		from ASCore import TSengine
		self.engine = TSengine()
		del TSengine

		TorrentPlayer.__init__(self)
Ejemplo n.º 3
0
    def info_hash(self):
        if not self._info_hash and self.is_finished():
            from base import TorrentPlayer
            tp = TorrentPlayer()
            tp.AddTorrent(self.saved_to)
            return tp.info_hash

        return self._info_hash
    def get_relative_torrent_files_list(self):
        from base import TorrentPlayer

        tp = TorrentPlayer()
        tp.AddTorrent(self.torrent)
        data = tp.GetLastTorrentData()
        files = data['files']

        return [filesystem.join(data['name'], item['name']) for item in files]
    def __init__(self, settings):
        self.engine = None
        self.file_id = None
        self.settings = settings
        self.download_path = None

        self.pre_buffer_bytes = self.debug_assignment(
            int(getSetting('pre_buffer_bytes')) * 1024 * 1024,
            'pre_buffer_bytes')

        self.debug('__init__')

        TorrentPlayer.__init__(self)
    def _GetLastTorrentData(self):
        while True:
            time.sleep(0.2)

            # Get torrent files list, filtered by video file type only
            files = self.engine.list()  #(media_types=[MediaType.VIDEO])
            # If torrent metadata is not loaded yet then continue
            if files is None:
                self.debug('files is None')
                continue

            self.debug('files len: ' + str(len(files)))

            # Torrent has no video files
            if not files or len(files) > 0:
                break

        info_hash = ''
        playable_items = []
        for item in files:
            if TorrentPlayer.is_playable(item.name):
                playable_items.append({
                    'index': item.index,
                    'name': item.name,
                    'size': long(item.size)
                })

        return {'info_hash': info_hash, 'files': playable_items}
Ejemplo n.º 7
0
def parse_torrent2(data):
    try:
        decoded = bdecode(data)
    except BTFailure:
        debug("Can't decode torrent data (invalid torrent link? %s)" % link)
        return

    files = []
    info = decoded['info']
    if 'files' in info:
        for i, f in enumerate(info['files']):
            # debug(i)
            # debug(f)
            fname = f['path'][-1]
            if TorrentPlayer.is_playable(fname):
                s = re.search('s(\d+)e(\d+)[\._ ]', fname, re.I)
                if s:
                    season = int(s.group(1))
                    episode = int(s.group(2))
                    debug(
                        'Filename: %s\t index: %d\t season: %d\t episode: %d' %
                        (fname, i, season, episode))
                    files.append({
                        'index': i,
                        'name': fname,
                        'season': season,
                        'episode': episode
                    })

    if len(files) == 0:
        return

    files.sort(key=lambda x: (x['season'], x['episode']))
    return files
Ejemplo n.º 8
0
	def GetLastTorrentData(self):
		'''
		return { 'info_hash': str, 'files': [ {'index': int, 'name': str, 'size': long} ] }
		'''
		
		'''
		As soon as check_torrent_added returns true, get added torrent data using get_last_added_torrent method. 
		This method will return a JSON object containing a torrent`s info-hash as a string (technically, this is 
		an info-hash hexdigest) and the list of files in the torrent along with their sizes. The info-hash is used 
		as a primary torrent ID for other JSON-RPC methods.
		'''
		files = []
		r = requests.post('http://localhost:8668/json-rpc', json={"method": "get_last_added_torrent"})
		torr_data = r.json()['result']
		debug(torr_data)
		
		self.__info_hash = torr_data['info_hash']
		
		
		index = 0
		for file in torr_data['files']:
			if TorrentPlayer.is_playable(file[0]):
				files.append({'index': index, 'name': file[0], 'size': long(file[1])})
			index = index + 1
			
		return { 'info_hash': self.__info_hash, 'files': files }
Ejemplo n.º 9
0
def parse_torrent2(data):
	try:
		decoded = bdecode(data)
	except BTFailure:
		debug("Can't decode torrent data (invalid torrent link? %s)" % link)
		return

	files = []
	info = decoded['info']
	if 'files' in info:
		for i, f in enumerate(info['files']):
			# debug(i)
			# debug(f)
			fname = f['path'][-1]
			if TorrentPlayer.is_playable(fname):
				s = re.search('s(\d+)e(\d+)[\._ ]', fname, re.I)
				if s:
					season = int(s.group(1))
					episode = int(s.group(2))
					debug('Filename: %s\t index: %d\t season: %d\t episode: %d' % (fname, i, season, episode))
					files.append({'index': i, 'name': fname, 'season': season, 'episode': episode})

	if len(files) == 0:
		return

	files.sort(key=lambda x: (x['season'], x['episode']))
	return files
Ejemplo n.º 10
0
def parse_torrent(data, season=None):
	from bencode import BTFailure
	try:
		from bencode import bdecode
		decoded = bdecode(data)
	except BTFailure:
		debug("Can't decode torrent data (invalid torrent link?)")
		return []

	info = decoded['info']
	dirlists = dict()
	#filelists = dict()
	if 'files' in info:
		for i, f in enumerate(info['files']):
			# debug(i)
			# debug(f)
			fname = f['path'][-1]
			try:
				parent = f['path'][-2]
			except:
				parent = '.'

			if parent not in dirlists:
				dirlists[parent] = dict()
				#filelists[parent] = dict()

			debug(fname)
			if TorrentPlayer.is_playable(fname):
				dirlists[parent][fname] = i  # .decode('utf-8').encode('cp1251')
				#filelists[parent].append({fname: i})

	files = []
	for dirname in dirlists:
		dirlist = dirlists[dirname]
		save_season = season
		for item in get_list(dirlist):
			if item is not None:
				if season is None:
					if item[0] is None:
						season = seasonfromname(info['name'])
						if season is None:
							try:
								season = seasonfromname(dirname)
							except:
								pass
					else:
						season = item[0]

				name = item[2]
				index = item[3]

				files.append({'name': name, 'season': season, 'episode': item[1], 'index': index})
				season = save_season
			else:
				# TODO
				continue

	files.sort(key=lambda x: (x['season'], x['episode']))
	return files
Ejemplo n.º 11
0
	def AddTorrent(self, path):
		'''
		Send a torrent to YATP usign add_torrent method. YATP accepts local and remote (http/https) 
		paths to .torrent files and magnet links. Warning: paths on networked filesystems (smb/nfs) are not supported!
		'''
		r = requests.post('http://localhost:8668/json-rpc', json={"method": "add_torrent", "params": {'torrent': path}})
		debug(r.json())

		TorrentPlayer.AddTorrent(self, path)
Ejemplo n.º 12
0
def scrape_nnm():
    from player import load_settings
    settings = load_settings()

    data_path = settings.torrents_path()

    if not filesystem.exists(filesystem.join(data_path, 'nnmclub')):
        return

    hashes = []
    for torr in filesystem.listdir(filesystem.join(data_path, 'nnmclub')):
        if torr.endswith('.torrent'):
            try:
                from base import TorrentPlayer
                tp = TorrentPlayer()
                tp.AddTorrent(filesystem.join(data_path, 'nnmclub', torr))
                data = tp.GetLastTorrentData()
                if data:
                    hashes.append((data['announce'], data['info_hash'],
                                   torr.replace('.torrent', '.stat')))
            except BaseException as e:
                log.print_tb(e)

    for chunk in chunks(hashes, 32):
        import scraper
        try:
            seeds_peers = scraper.scrape(chunk[0][0], [i[1] for i in chunk],
                                         10)
        except RuntimeError as RunE:
            if '414 status code returned' in RunE.message:
                for c in chunks(chunk, 16):
                    try:
                        seeds_peers = scraper.scrape(c[0][0],
                                                     [i[1] for i in c], 10)
                        process_chunk(c, data_path, seeds_peers)
                    except BaseException as e:
                        log.print_tb(e)
            continue
        except BaseException as e:
            log.print_tb(e)
            continue

        process_chunk(chunk, data_path, seeds_peers)
    def all_torrent_files_exists(self):
        from base import TorrentPlayer
        tp = TorrentPlayer()
        tp.AddTorrent(self.torrent)
        data = tp.GetLastTorrentData()
        files = data['files']

        for item in files:
            path = filesystem.join(self.storage_path, data['name'],
                                   item['name'])
            debug(u'all_torrent_files_exists: ' + path)
            if not filesystem.exists(path):
                path = filesystem.join(self.settings.copy_video_path,
                                       data['name'], item['name'])
                debug(u'all_torrent_files_exists: ' + path)
                if not filesystem.exists(path):
                    debug(u'all_torrent_files_exists: not found')
                    return False

        debug(u'all_torrent_files_exists: Ok')
        return True
    def CheckTorrentAdded(self):
        if self.engine:
            status = self.engine.status()
            self.engine.check_torrent_error(status)

            self.debug('CheckTorrentAdded')

            if status.state == State.CHECKING_FILES:
                self.debug('State.CHECKING_FILES')
                return False
        else:
            return TorrentPlayer.CheckTorrentAdded(self)

        return True
    def relativevideofile(self):
        with filesystem.fopen(self.torrent_path, 'rb') as torr:
            data = torr.read()

            if data is None:
                return self.playable_item['name']

            from bencode import BTFailure
            try:
                from bencode import bdecode
                decoded = bdecode(data)
            except BTFailure:
                debug("Can't decode torrent data (invalid torrent link?)")
                return self.playable_item['name']

            info = decoded['info']

            if 'files' in info:
                from base import TorrentPlayer
                return filesystem.join(TorrentPlayer.Name(info['name']),
                                       self.playable_item['name'])

        return self.playable_item['name']
Ejemplo n.º 16
0
def parse_torrent(data, season=None):
    from bencode import BTFailure
    try:
        from bencode import bdecode
        decoded = bdecode(data)
    except BTFailure:
        debug("Can't decode torrent data (invalid torrent link?)")
        return []

    info = decoded['info']
    dirlists = dict()
    #filelists = dict()
    if 'files' in info:
        for i, f in enumerate(info['files']):
            # debug(i)
            # debug(f)
            fname = f['path'][-1]
            try:
                parent = f['path'][-2]
            except:
                parent = '.'

            if parent not in dirlists:
                dirlists[parent] = dict()
                #filelists[parent] = dict()

            debug(fname)
            if TorrentPlayer.is_playable(fname):
                dirlists[parent][
                    fname] = i  # .decode('utf-8').encode('cp1251')
                #filelists[parent].append({fname: i})

    files = []
    for dirname in dirlists:
        dirlist = dirlists[dirname]
        save_season = season
        for item in get_list(dirlist):
            if item is not None:
                if season is None:
                    if item[0] is None:
                        season = seasonfromname(info['name'])
                        if season is None:
                            try:
                                season = seasonfromname(dirname)
                            except:
                                pass
                    else:
                        season = item[0]

                name = item[2]
                index = item[3]

                files.append({
                    'name': name,
                    'season': season,
                    'episode': item[1],
                    'index': index
                })
                season = save_season
            else:
                # TODO
                continue

    files.sort(key=lambda x: (x['season'], x['episode']))
    return files