2010-06-26 16:32:08 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
# vi:si:et:sw=4:sts=4:ts=4
|
2012-01-11 13:12:32 +05:30
|
|
|
import os
|
|
|
|
|
from datetime import timedelta, datetime
|
|
|
|
|
import gzip
|
2012-02-15 23:32:06 +05:30
|
|
|
import random
|
|
|
|
|
random
|
2012-01-11 13:12:32 +05:30
|
|
|
|
|
|
|
|
from django.conf import settings
|
|
|
|
|
from ox.utils import ET
|
2011-12-27 18:51:22 +05:30
|
|
|
from celery.task import task, periodic_task
|
2010-06-26 16:32:08 +02:00
|
|
|
|
|
|
|
|
import models
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@periodic_task(run_every=timedelta(days=1))
|
|
|
|
|
def cronjob(**kwargs):
|
2012-02-15 23:32:06 +05:30
|
|
|
update_random_sort()
|
|
|
|
|
|
|
|
|
|
def update_random_sort():
|
|
|
|
|
if filter(lambda f: f['id'] == 'random', settings.CONFIG['itemKeys']):
|
|
|
|
|
random.seed()
|
|
|
|
|
ids = [f['item'] for f in models.ItemSort.objects.values('item')]
|
|
|
|
|
random.shuffle(ids)
|
2012-02-22 17:58:42 +05:30
|
|
|
n = 1
|
2012-02-15 23:32:06 +05:30
|
|
|
for i in ids:
|
|
|
|
|
models.ItemSort.objects.filter(pk=i).update(random=n)
|
|
|
|
|
n += 1
|
2011-01-01 17:14:42 +05:30
|
|
|
|
2012-03-08 19:56:31 +01:00
|
|
|
def update_random_clip_sort():
|
|
|
|
|
if filter(lambda f: f['id'] == 'random', settings.CONFIG['itemKeys']):
|
|
|
|
|
random.seed()
|
|
|
|
|
from clip.models import Clip
|
|
|
|
|
ids = [f['id'] for f in Clip.objects.values('id')]
|
|
|
|
|
random.shuffle(ids)
|
|
|
|
|
n = 1
|
|
|
|
|
for i in ids:
|
|
|
|
|
Clip.objects.filter(pk=i).update(random=n)
|
|
|
|
|
n += 1
|
|
|
|
|
|
2010-09-10 17:12:22 +02:00
|
|
|
@task(ignore_resulsts=True, queue='default')
|
2010-11-27 13:12:53 +01:00
|
|
|
def update_poster(itemId):
|
2010-09-23 18:01:48 +02:00
|
|
|
item = models.Item.objects.get(itemId=itemId)
|
2010-12-01 01:00:33 +01:00
|
|
|
item.make_poster(True)
|
2011-01-21 16:19:24 +05:30
|
|
|
item.make_icon()
|
2011-10-28 20:27:54 +02:00
|
|
|
item.save()
|
2011-01-01 17:14:42 +05:30
|
|
|
|
2010-07-12 16:56:14 +02:00
|
|
|
@task(ignore_resulsts=True, queue='default')
|
2011-01-16 18:58:57 +05:30
|
|
|
def update_external(itemId):
|
2010-12-25 19:15:19 +05:30
|
|
|
item = models.Item.objects.get(itemId=itemId)
|
2011-01-16 18:58:57 +05:30
|
|
|
item.update_external()
|
2010-06-26 16:32:08 +02:00
|
|
|
|
2011-08-19 18:54:42 +02:00
|
|
|
@task(queue="default")
|
|
|
|
|
def update_timeline(itemId):
|
2010-10-16 13:49:45 +02:00
|
|
|
item = models.Item.objects.get(itemId=itemId)
|
2011-08-19 18:54:42 +02:00
|
|
|
item.update_timeline()
|
2011-06-01 18:40:39 +02:00
|
|
|
|
2011-09-14 10:50:18 -04:00
|
|
|
@task(queue="default")
|
2011-06-01 18:40:39 +02:00
|
|
|
def load_subtitles(itemId):
|
|
|
|
|
item = models.Item.objects.get(itemId=itemId)
|
2011-08-20 12:06:18 +02:00
|
|
|
item.load_subtitles()
|
2011-06-02 10:19:15 +02:00
|
|
|
|
2012-01-11 13:12:32 +05:30
|
|
|
@task(ignore_resulsts=True, queue='default')
|
|
|
|
|
def update_sitemap(base_url):
|
|
|
|
|
sitemap = os.path.abspath(os.path.join(settings.MEDIA_ROOT, 'sitemap.xml.gz'))
|
|
|
|
|
|
|
|
|
|
def absolute_url(url):
|
|
|
|
|
return base_url + url
|
|
|
|
|
|
|
|
|
|
urlset = ET.Element('urlset')
|
|
|
|
|
urlset.attrib['xmlns'] = "http://www.sitemaps.org/schemas/sitemap/0.9"
|
|
|
|
|
urlset.attrib['xmlns:xsi'] = "http://www.w3.org/2001/XMLSchema-instance"
|
|
|
|
|
urlset.attrib['xsi:schemaLocation'] = "http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"
|
|
|
|
|
urlset.attrib['xmlns:video']= "http://www.google.com/schemas/sitemap-video/1.0"
|
|
|
|
|
|
|
|
|
|
url = ET.SubElement(urlset, "url")
|
|
|
|
|
loc = ET.SubElement(url, "loc")
|
|
|
|
|
loc.text = absolute_url('')
|
|
|
|
|
# always, hourly, daily, weekly, monthly, yearly, never
|
|
|
|
|
changefreq = ET.SubElement(url, "changefreq")
|
|
|
|
|
changefreq.text = 'daily'
|
|
|
|
|
# This date should be in W3C Datetime format, can be %Y-%m-%d
|
|
|
|
|
lastmod = ET.SubElement(url, "lastmod")
|
|
|
|
|
lastmod.text = datetime.now().strftime("%Y-%m-%d")
|
|
|
|
|
# priority of page on site values 0.1 - 1.0
|
|
|
|
|
priority = ET.SubElement(url, "priority")
|
|
|
|
|
priority.text = '1.0'
|
|
|
|
|
|
|
|
|
|
for page in [s['id'] for s in settings.CONFIG['sitePages']]:
|
|
|
|
|
url = ET.SubElement(urlset, "url")
|
|
|
|
|
loc = ET.SubElement(url, "loc")
|
|
|
|
|
loc.text = absolute_url(page)
|
|
|
|
|
# always, hourly, daily, weekly, monthly, yearly, never
|
|
|
|
|
changefreq = ET.SubElement(url, "changefreq")
|
|
|
|
|
changefreq.text = 'monthly'
|
|
|
|
|
# priority of page on site values 0.1 - 1.0
|
|
|
|
|
priority = ET.SubElement(url, "priority")
|
|
|
|
|
priority.text = '1.0'
|
|
|
|
|
|
|
|
|
|
allowed_level = settings.CONFIG['capabilities']['canSeeItem']['guest']
|
|
|
|
|
for i in models.Item.objects.filter(level__lte=allowed_level):
|
|
|
|
|
url = ET.SubElement(urlset, "url")
|
|
|
|
|
# URL of the page. This URL must begin with the protocol (such as http)
|
|
|
|
|
loc = ET.SubElement(url, "loc")
|
|
|
|
|
loc.text = absolute_url("%s" % i.itemId)
|
|
|
|
|
# This date should be in W3C Datetime format, can be %Y-%m-%d
|
|
|
|
|
lastmod = ET.SubElement(url, "lastmod")
|
|
|
|
|
lastmod.text = i.modified.strftime("%Y-%m-%d")
|
|
|
|
|
# always, hourly, daily, weekly, monthly, yearly, never
|
|
|
|
|
changefreq = ET.SubElement(url, "changefreq")
|
|
|
|
|
changefreq.text = 'monthly'
|
|
|
|
|
# priority of page on site values 0.1 - 1.0
|
|
|
|
|
priority = ET.SubElement(url, "priority")
|
|
|
|
|
priority.text = '1.0'
|
|
|
|
|
video = ET.SubElement(url, "video:video")
|
|
|
|
|
#el = ET.SubElement(video, "video:content_loc")
|
|
|
|
|
#el.text = absolute_url("%s/video" % i.itemId)
|
|
|
|
|
el = ET.SubElement(video, "video:player_loc")
|
|
|
|
|
el.attrib['allow_embed'] = 'no'
|
|
|
|
|
el.text = absolute_url("%s/video" % i.itemId)
|
|
|
|
|
el = ET.SubElement(video, "video:title")
|
|
|
|
|
el.text = i.get('title')
|
|
|
|
|
el = ET.SubElement(video, "video:thumbnail_loc")
|
|
|
|
|
icon = settings.CONFIG['user']['ui']['icons'] == 'frames' and 'icon' or 'poster'
|
2012-01-11 17:52:59 +05:30
|
|
|
el.text = absolute_url("%s/%s256.jpg" %(i.itemId, icon))
|
2012-01-11 13:12:32 +05:30
|
|
|
description = i.get('description', i.get('summary', ''))
|
|
|
|
|
if description:
|
|
|
|
|
el = ET.SubElement(video, "video:description")
|
|
|
|
|
el.text = i.get('description', i.get('summary', ''))
|
|
|
|
|
el = ET.SubElement(video, "video:family_friendly")
|
|
|
|
|
el.text = 'Yes'
|
2012-01-11 17:52:59 +05:30
|
|
|
duration = i.sort.duration
|
|
|
|
|
if duration > 0:
|
2012-01-11 13:12:32 +05:30
|
|
|
el = ET.SubElement(video, "video:duration")
|
2012-01-11 17:52:59 +05:30
|
|
|
el.text = "%s" % int(duration)
|
2012-01-11 13:12:32 +05:30
|
|
|
|
2012-01-11 13:21:26 +05:30
|
|
|
with open(sitemap[:-3], 'wb') as f:
|
|
|
|
|
f.write('<?xml version="1.0" encoding="UTF-8"?>\n' + ET.tostring(urlset))
|
2012-01-11 13:12:32 +05:30
|
|
|
with gzip.open(sitemap, 'wb') as f:
|
|
|
|
|
f.write('<?xml version="1.0" encoding="UTF-8"?>\n' + ET.tostring(urlset))
|