Trouve les bons noms :D
This commit is contained in:
parent
c8f00f0a4c
commit
b8825bb213
3 changed files with 9 additions and 10 deletions
|
@ -1,16 +1,16 @@
|
|||
from urllib.parse import parse_qs
|
||||
import requests
|
||||
import json
|
||||
|
||||
from django.db import models, migrations, transaction
|
||||
YOUTUBE_INFO_URL = 'http://youtube.com/get_video_info?video_id={}'
|
||||
YOUTUBE_INFO_URL = 'http://www.youtube.com/oembed?url=http://www.youtube.com/watch?v={}&format=json'
|
||||
|
||||
def gen_title(apps, schema_editor):
|
||||
Link = apps.get_model('player', 'Link')
|
||||
for o in Link.objects.all():
|
||||
response = requests.get(YOUTUBE_INFO_URL.format(o.token))
|
||||
q = parse_qs(response.content.decode('utf-8'))
|
||||
q = json.loads(response.content.decode('utf-8'))
|
||||
try:
|
||||
o.title = q['title'][0]
|
||||
o.title = q['title']
|
||||
except KeyError:
|
||||
o.delete()
|
||||
else:
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
from urllib.parse import parse_qs
|
||||
import requests
|
||||
import json
|
||||
|
||||
from django.db import models
|
||||
from django.shortcuts import reverse
|
||||
|
||||
PK_LENGTH = 23
|
||||
YOUTUBE_INFO_URL = 'http://youtube.com/get_video_info?video_id={}'
|
||||
YOUTUBE_INFO_URL = 'http://www.youtube.com/oembed?url=http://www.youtube.com/watch?v={}&format=json'
|
||||
|
||||
class Playlist(models.Model):
|
||||
date = models.DateTimeField(verbose_name="date")
|
||||
|
@ -61,5 +61,5 @@ class Link(models.Model):
|
|||
def update_titles(cls):
|
||||
for o in cls.objects.all():
|
||||
response = requests.get(YOUTUBE_INFO_URL.format(o.token))
|
||||
o.title = parse_qs(response.content.decode('utf-8'))['title'][0]
|
||||
o.title = json.loads(response.content.decode('utf-8'))['title']
|
||||
o.save()
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import json
|
||||
import requests
|
||||
from urllib.parse import parse_qs
|
||||
|
||||
from django.shortcuts import render, get_object_or_404, redirect
|
||||
from django.http import HttpResponse
|
||||
|
@ -53,8 +52,8 @@ def add_link(request, token):
|
|||
yt_token = l.get_token()
|
||||
response = requests.get(YOUTUBE_INFO_URL.format(yt_token))
|
||||
try:
|
||||
q = parse_qs(response.content.decode('utf-8'))
|
||||
title = q['title'][0]
|
||||
q = json.loads(response.content.decode('utf-8'))
|
||||
title = q['title']
|
||||
except KeyError:
|
||||
title = "Je n'arrive pas à retrouver le titre :("
|
||||
p.last_update = timezone.now()
|
||||
|
|
Loading…
Reference in a new issue