예제 #1
0
def home(id):
    vid = Video.objects.all()
    output = "expire=" + str(time.time()) + "&"
    for v in vid:
        if v.vid == id and len(v.url) > 5:
            try:
                exptime = extract(v.url, "expire=", "&")
            except:
                break
            print "exp " + str(exptime)
            print "cur " + str(time.time())
            if float(exptime) - float(time.time()) > 0:
                print float(exptime) - float(time.time())
                print "Returning " + v.url
                return v.url
            else:
                try:
                    output = subprocess.check_output(["youtube-dl", "-g", id])
                    Video.objects.filter(vid=v.vid).update(set__url=output)
                except:
                    pass
                return output
            break
    try:
        output = subprocess.check_output(["youtube-dl", "-g", id])
    except:
        pass
    video = Video(title="id", vid=id, url=output)
    try:
        video.save()
    except:
        Video.objects.filter(vid=id).update(set__url=output)
    return output
예제 #2
0
def hello_img(id):
    # video=Video(title="id", vid="id")
    # video.save()
    vid = Video.objects.all()
    for v in vid:
        print v.id
        print v.url
        if v.vid == id and len(v.url) > 5:
            return v.url
    output = subprocess.check_output(["youtube-dl", "-g", id])
    video = Video(title="id", vid=id, url=output)
    video.save()
    return output