Пример #1
0
    def save(self):
	self.slug = slughifi(self.title)
	if not re.sub('\s+-', '', self.slug) or len(self.slug) > 50:
	    self.slug = genslug()
	self.slug = self.slug.replace(' ', '-')
	self.author.attrs['posts'] = Topic.objects.filter(author=self.author).count()
	self.author.save()
	try:
	    super(Topic, self).save()
	except:
	    self.slug = genslug()
	    super(Topic, self).save()
Пример #2
0
 def save(self):
     self.slug = slughifi(self.title)
     if not re.sub('\s+-', '', self.slug) or len(self.slug) > 50:
         self.slug = genslug()
     self.slug = self.slug.replace(' ', '-')
     self.author.attrs['posts'] = Topic.objects.filter(
         author=self.author).count()
     self.author.save()
     try:
         super(Topic, self).save()
     except:
         self.slug = genslug()
         super(Topic, self).save()
Пример #3
0
def _save_torrent(instance, data):
    from utils import slughifi, genslug
    import base64
    if not data:
	return
    slug = slughifi(instance.title)
    if not slug.strip().replace('-', '') or len(slug)>=50:
	slug = genslug()
    slug = slug.replace(' ', '-')
    fn = "%sxDF-%s.torrent"%(instance.author.id, slug)
    torrent = Torrent()
    torrent.fn = fn
    torrent.author = instance.author
    torrent.info_hash = data[1]
    if data[0]['info'].has_key('length'):
	file_length = data[0]['info']['length']
    else:
	file_length = reduce(lambda x,y: x+y, [f['length'] for f in data[0]['info']['files']])
    torrent.bytes = file_length
    hsh = base64.b64encode(bencode(data[0]))
    torrent.info = hsh
    torrent.save()
    instance.torrent = torrent
def _save_torrent(instance, data):
    from utils import slughifi, genslug
    import base64
    if not data:
        return
    slug = slughifi(instance.title)
    if not slug.strip().replace('-', '') or len(slug) >= 50:
        slug = genslug()
    slug = slug.replace(' ', '-')
    fn = "%sxDF-%s.torrent" % (instance.author.id, slug)
    torrent = Torrent()
    torrent.fn = fn
    torrent.author = instance.author
    torrent.info_hash = data[1]
    if data[0]['info'].has_key('length'):
        file_length = data[0]['info']['length']
    else:
        file_length = reduce(lambda x, y: x + y,
                             [f['length'] for f in data[0]['info']['files']])
    torrent.bytes = file_length
    hsh = base64.b64encode(bencode(data[0]))
    torrent.info = hsh
    torrent.save()
    instance.torrent = torrent
Пример #5
0
 def save(self, *args, **kwargs):
     self.slug = slughifi(self.nombre)
     self.slug = self.slug.lower()
     super(Categoria, self).save(*args, **kwargs)
    def __init__(self, path):
        self.info = {}
        try:
            info = metadata.parse(os.path.normpath(path))
        except:
            sys.stderr.write("METADATA, problem with %s" % path)
            return
        if not info:
            self.info = {}
            return
        if not hasattr(info, 'mime'):
            self.info = {}
            return
        if not info.mime:
            self.info = {}
            return
        self.mime = info.mime

        if info.mime not in mimes: mimes.append(info.mime)

        if info.mime == 'audio/wav':
            self.info = {'samplerate': info.samplerate}
            self.icon = 'icon-snd'
        elif info.mime.startswith('audio') or info.mime.endswith('ogg'):
            self.icon = 'icon-snd'
            try:
                pattern = ""
                if info.has_key('title'):
                    if info.title:
                        title = info.title.encode("latin_1")
                        pattern += title
                if info.has_key('artist'):
                    if info.artist:
                        artist = info.artist.encode("latin_1")
                        pattern += " " + artist
                if info.has_key('album'):
                    if info.album:
                        album = info.album.encode("latin_1")
                        pattern += " " + album
                if info.has_key('comment'):
                    if len(info.comment) > 0:
                        comment = info.comment.encode("latin_1")
                        pattern += " " + comment
                if pattern:
                    enc = chardet.detect(pattern)['encoding']
                    if enc == 'EUC-TW' or enc == 'windows-1255' or enc == 'MacCyrillic' or enc == 'TIS-620' or enc == 'KOI8-R' or enc == 'IBM866':
                        enc = 'CP1251'
                    elif not enc or enc.startswith('ISO-8859'):
                        enc = "latin1"
                else:
                    enc = None
            except:
                if info.has_key('title'):
                    if info.title:
                        title = slughifi(info.title)
                if info.has_key('artist'):
                    if len(info.artist) > 0:
                        artist = slughifi(info.artist)
                if info.has_key('album'):
                    if info.album:
                        album = slughifi(info.album)
                if info.has_key('comment'):
                    if info.comment:
                        comment = slughifi(info.comment)
                enc = None

            for key in ['samplerate', 'date', 'bitrate', 'trackno']:
                if hasattr(info, i):
                    self.info[key] = getattr(info, key)
            if hasattr(info, 'length'):
                self.info['length'] = info.length  # getPlayTimeString(value)
            if hasattr(info, 'comment'):
                try:
                    tmp = value.encode("latin_1")
                    try:
                        tmp = unicode(tmp, chardet.detect(tmp)['encoding'])
                    except:
                        tmp = re.sub('[^a-zA-Z0-9\\s\\-]{1}', replace_char,
                                     value).lower()
                except:
                    tmp = re.sub('[^a-zA-Z0-9\\s\\-]{1}', replace_char,
                                 value).lower()
                if re.sub('\s+', '', tmp):
                    self.info['comment'] = tmp

                if hasattr(info, 'album') and enc:
                    try:
                        self.info['album'] = unicode(album, enc)
                    except UnicodeEncodeError:
                        self.info['album'] = slughifi(album)
                if hasattr(info, 'artist') and enc:
                    try:
                        self.info['artist'] = unicode(artist, enc)
                    except UnicodeEncodeError:
                        self.info['artist'] = slughifi(artist)
                if hasattr(info, 'title') and enc:
                    try:
                        self.info['title'] = unicode(title, enc)
                    except UnicodeEncodeError:
                        self.info['title'] = slughifi(title)

        elif info.mime.startswith('video') or \
            info.mime == 'application/ogm' or \
            info.mime == 'application/mkv':
            if info.mime.endswith('x-msvideo'): self.icon = 'icon-avi'
            else: self.icon = 'icon-vid'
            for key in ['comment', 'producer', 'genre', 'country']:
                if hasattr(info, key):
                    self.info[key] = getattr(info, key)
            if hasattr(info, 'length'):
                self.info['length'] = info.length  #getPlayTimeString(value)
            if hasattr(info, 'all_header'):
                if len(info.all_header) > 0:
                    for k in info.all_header[0]:
                        self.info[k] = info.all_header[0][k]
            try:
                if info.video[0].codec:
                    self.info['codec'] = info.video[0].codec
                if info.video[0].fps:
                    self.info['fps'] = "%.0d" % info.video[0].fps
                if info.video[0].width:
                    self.info['width'] = info.video[0].width
                if info.video[0].height:
                    self.info['height'] = info.video[0].height
                if info.header['INFO']['ISRC']:
                    self.info['source'] = info.header['INFO']['ISRC']
            except:
                pass
    def __init__(self, path):
	self.info = {}
	try:
	    info = metadata.parse(os.path.normpath(path))
	except:
	    sys.stderr.write("METADATA, problem with %s" % path)
	    return
	if not info:
	    self.info = {}
	    return
	if not hasattr(info, 'mime'):
	    self.info = {}
	    return
	if not info.mime:
	    self.info = {}
	    return
	self.mime = info.mime
	
	if info.mime not in mimes: mimes.append(info.mime)
	
	if info.mime == 'audio/wav':
	    self.info = {'samplerate': info.samplerate}
	    self.icon = 'icon-snd'
        elif info.mime.startswith('audio') or info.mime.endswith('ogg'):
	    self.icon = 'icon-snd'
	    try:
		pattern=""
		if info.has_key('title'):
		    if info.title:
			title = info.title.encode("latin_1")
			pattern+=title
		if info.has_key('artist'):
		    if info.artist:
			artist = info.artist.encode("latin_1")
		        pattern+=" "+artist
		if info.has_key('album'):
		    if info.album:
			album = info.album.encode("latin_1")
			pattern+=" "+album
		if info.has_key('comment'):
		    if len(info.comment) > 0:
			comment = info.comment.encode("latin_1")
			pattern+=" "+comment
		if pattern:
		    enc = chardet.detect(pattern)['encoding']
		    if enc == 'EUC-TW' or enc == 'windows-1255' or enc == 'MacCyrillic' or enc == 'TIS-620' or enc == 'KOI8-R' or enc == 'IBM866':
			enc = 'CP1251'
		    elif not enc or enc.startswith('ISO-8859'):
			enc = "latin1"
		else:
		    enc = None
	    except:
		if info.has_key('title'):
		    if info.title:
			title = slughifi(info.title)
		if info.has_key('artist'):
		    if len(info.artist) > 0:
			artist = slughifi(info.artist)
		if info.has_key('album'):
		    if info.album:
			album = slughifi(info.album)
		if info.has_key('comment'):
		    if info.comment:
			comment = slughifi(info.comment)
		enc = None

	    for key in ['samplerate', 'date', 'bitrate', 'trackno']:
		if hasattr(info, i):
		    self.info[key] = getattr(info, key)
	    if hasattr(info, 'length'):
		self.info['length'] = info.length # getPlayTimeString(value)
	    if hasattr(info, 'comment'):
		try:
		    tmp=value.encode("latin_1")
		    try:
			tmp = unicode(tmp, chardet.detect(tmp)['encoding'])
		    except:
			tmp=re.sub('[^a-zA-Z0-9\\s\\-]{1}', replace_char, value).lower()
		except:
		    tmp=re.sub('[^a-zA-Z0-9\\s\\-]{1}', replace_char, value).lower()
		if re.sub('\s+','',tmp):
		    self.info['comment'] = tmp

		if hasattr(info, 'album') and enc:
		    try:
			self.info['album'] = unicode(album, enc)
		    except UnicodeEncodeError:
			self.info['album'] = slughifi(album)
		if hasattr(info, 'artist') and enc:
		    try:
			self.info['artist'] = unicode(artist, enc)
		    except UnicodeEncodeError:
			self.info['artist'] = slughifi(artist)
		if hasattr(info, 'title') and enc:
		    try:
			self.info['title'] = unicode(title, enc)
		    except UnicodeEncodeError:
			self.info['title'] = slughifi(title)

	elif info.mime.startswith('video') or \
	    info.mime == 'application/ogm' or \
	    info.mime == 'application/mkv':
	    if info.mime.endswith('x-msvideo'): self.icon = 'icon-avi'
	    else: self.icon = 'icon-vid'
	    for key in ['comment', 'producer', 'genre', 'country']:
		if hasattr(info, key):
		    self.info[key] = getattr(info, key)
	    if hasattr(info, 'length'):
		self.info['length'] = info.length #getPlayTimeString(value)
	    if hasattr(info, 'all_header'):
		if len(info.all_header) > 0:
		    for k in info.all_header[0]:
			self.info[k] = info.all_header[0][k]
	    try:
		if info.video[0].codec:
		    self.info['codec'] = info.video[0].codec
		if info.video[0].fps:
		    self.info['fps'] = "%.0d" % info.video[0].fps
		if info.video[0].width:
		    self.info['width'] = info.video[0].width
		if info.video[0].height:
		    self.info['height'] = info.video[0].height
		if info.header['INFO']['ISRC']:
		    self.info['source'] = info.header['INFO']['ISRC']
	    except:
		pass