]> git.parisson.com Git - telemeta.git/commitdiff
auto parsing youtube titles
authoryomguy <yomguy@parisson.com>
Fri, 4 Nov 2011 11:46:48 +0000 (12:46 +0100)
committeryomguy <yomguy@parisson.com>
Fri, 4 Nov 2011 11:46:48 +0000 (12:46 +0100)
INSTALL.rst
telemeta/web/base.py

index a0b6e6331c322a45db1136ce7da4b168f63621af..18b8812c579ef3085653a37e0ef986ce121eac5c 100644 (file)
@@ -45,7 +45,7 @@ Install the dependencies
        
         sudo aptitude install python python-django python-xml python-mysqldb mysql-server \
                               python-ctypes python-setuptools python-support python-docutils \
-                              python-libxml2 python-django-registration
+                              python-libxml2 python-django-registration python-lxml
 
     To get MP3 reading and writing, just add these lines to your /etc/apt/sources-list::
 
index 70c99df062238662a21326336464e8e167da1b26..ec3fa80e1bb9eadb5314bc02ec9d6070601ae712 100644 (file)
@@ -512,7 +512,15 @@ class ItemView(object):
                 file.set_mime_type()
                 file.save()
             if not file.title and file.url:
-                file.title = file.url
+                try:
+                    from lxml import etree
+                    parser = etree.HTMLParser()
+                    tree = etree.parse(file.url, parser)
+                    title = tree.find(".//title").text
+                    title = title.replace('\n', '').strip()
+                    file.title = title
+                except:
+                    file.title = file.url
                 file.save()
                 
         return render(request, template,