Пример #1
0
def personal_post_video_create(request, *, name, video_type, sub_video_type,
                               price, dir_num, describe):
    if not name or not name.strip():
        raise APIValueError('name', 'name cannot be empty.')
    if not video_type or not video_type.strip():
        raise APIValueError('video_type', 'video_type cannot be empty.')
    if not sub_video_type or not sub_video_type.strip():
        raise APIValueError('sub_video_type',
                            'sub_video_type cannot be empty.')
    if not describe or not describe.strip():
        raise APIValueError('describe', 'describe cannot be empty.')
    video = Video(name=name.strip(),
                  video_type=video_type.strip(),
                  sub_video_type=sub_video_type.strip(),
                  pic_path='null',
                  user_name=request.__user__.name,
                  describe=describe.strip(),
                  user_id=request.__user__.id,
                  price=price,
                  dir_num=dir_num,
                  people_num=0)
    yield from video.save()
    #these code is not strong,should be use subprocess
    path = '../static/video/' + request.__user__.email + '/' + video.id + '/'
    pic_path = path + 'video_pic'
    video.pic_path = pic_path
    yield from video.update()
    os.chdir(
        '/home/luohaixian/software/myproject/learning_online/www/templates')
    os.system('mkdir ' + path)
    os.system('cp ../static/src/test.png ' + pic_path)
    return video
Пример #2
0
def manage_get_video(*, page='1'):
    page_index = get_page_index(page)
    num = yield from Video.findNumber('count(*)')
    p = Page(num, page_index, 1)
    videos = yield from Video.findAll(orderBy="created_at desc",
                                      limit=(p.offset, p.limit))
    return dict(videos=videos, page=p)
Пример #3
0
def get_random_video():
    if not Video.query().get():
        return
    random_float = random.uniform(0, get_max_random())
    return Video.query() \
        .order(Video.random) \
        .filter(Video.approved == True, Video.random >= random_float).get()
Пример #4
0
def add_video_to_db(video_url, thumbnail_url, video_type, object_id, username=None):
    if not Video.query.filter(Video.url==video_url).count():
        v = Video(url=video_url, thumbnail=thumbnail_url, video_type=video_type, object_id=object_id)
        if username:
            v.username=username
        db.session.add(v)
        db.session.commit()
Пример #5
0
 def add_video(self, videoID="asdf", title="title", star=False):
     v = Video(user=self.get_user(),
               videoID=videoID,
               title=title,
               star=star)
     v.save()
     return v
Пример #6
0
def new_video():
    form = VideoForm()
    if form.validate_on_submit():
        now = moment.now().format('dddd, MMMM D YYYY')
        today = Day.query.filter_by(date=now).first()
        if today is not None:
            video = Video(title=form.title.data,description=form.description.data,video_link=form.video_link.data,day_id=today.id)
            db.session.add(video)
            db.session.flush()
            video.generate_hash()
            video.generate_thumbnail(app.config["UPLOAD_FOLDER"], form.thumbnail.data, app.config["ALLOWED_EXTENSIONS"])
            db.session.add(video)
            db.session.commit()
            flash("Video Successfully Added")
            return redirect(url_for("index"))
        else:
            day = Day(date=now)
            db.session.add(day)
            db.session.flush()
            video = Video(title=form.title.data,description=form.description.data,video_link=form.video_link.data,day_id=day.id)
            db.session.add(video)
            db.session.flush()
            video.generate_hash()
            video.generate_thumbnail(app.config["UPLOAD_FOLDER"], form.thumbnail.data, app.config["ALLOWED_EXTENSIONS"])
            db.session.add(video)
            db.session.commit()
            flash("Video Successfully Added")
            return redirect(url_for("index"))
    return render_template("videos/new.html",form=form)
Пример #7
0
 def updateVideoAndPlaylistReadableNames(self):
     # Makes sure every video and playlist has a unique "name" that can be used in URLs
     query = Video.all()
     all_videos = query.fetch(100000)
     for video in all_videos:
         potential_id = re.sub('[^a-z0-9]', '-', video.title.lower())
         potential_id = re.sub(
             '-+$', '',
             potential_id)  # remove any trailing dashes (see issue 1140)
         potential_id = re.sub(
             '^-+', '',
             potential_id)  # remove any leading dashes (see issue 1526)
         if video.readable_id == potential_id:  # id is unchanged
             continue
         number_to_add = 0
         current_id = potential_id
         while True:
             query = Video.all()
             query.filter('readable_id=', current_id)
             if (query.get() is
                     None):  #id is unique so use it and break out
                 video.readable_id = current_id
                 video.put()
                 break
             else:  # id is not unique so will have to go through loop again
                 number_to_add += 1
                 current_id = potential_id + '-' + number_to_add
Пример #8
0
    def test_parse_video(self):

        owner = GroupFactory(remote_id=GROUP_ID)
        album = AlbumFactory(remote_id=ALBUM_ID, owner=owner)

        response = '''{"photo_130": "http://cs313422.vk.me/u163668241/video/s_6819a7d1.jpg",
            "repeat": 0,
            "photo_320": "http://cs313422.vk.me/u163668241/video/l_4cc8a38a.jpg",
            "description": "bla bla bla",
            "title": "Эстафета Олимпийского огня «Сочи 2014». Неделя 3-я",
            "can_repost": 1, "views": 928, "album_id": 50850761, "comments": 12, "player": "http://www.youtube.com/embed/UmDAmM53bU0", "date": 1386074580, "likes": {"count": 191, "user_likes": 0}, "duration": 206, "can_comment": 1, "id": 166742757, "owner_id": -16297716}
        '''
        d = json.loads(response)

        instance = Video()
        instance.parse(d.copy())
        instance.save()

        self.assertEqual(instance.album, album)
        self.assertEqual(instance.owner, owner)

        self.assertEqual(instance.remote_id, d['id'])
        self.assertEqual(instance.title, d['title'])
        self.assertEqual(instance.description, d['description'])
        self.assertEqual(instance.photo_130, d['photo_130'])
        self.assertEqual(instance.player, d['player'])
        self.assertEqual(instance.views_count, d['views'])
        self.assertEqual(instance.comments_count, d['comments'])
        self.assertEqual(instance.likes_count, d['likes']['count'])
        self.assertEqual(instance.duration, d['duration'])

        self.assertIsNotNone(instance.date)
Пример #9
0
def save_manifest_in_model(house_id, m3u8_manifest):
    
    # 
    # Search de Video, if exist return Error
    try:
	video = Video.objects.get(house_id=house_id)
	return False
    except:
	video = Video()
	video.house_id = house_id
	video.format   = 'hls'
	video.save()

    for rendition in m3u8_manifest.files:
	profile = Profile()
	profile.video = video
	profile.bandwidth  	= rendition['bandwidth']
        profile.average    	= rendition['average']
        profile.codecs     	= rendition['codecs']
        profile.resolution 	= rendition['resolution']
        profile.filename   	= rendition['filename']
	profile.version	   	= rendition['rendition'].header['version']
	profile.media_seq  	= rendition['rendition'].header['media_seq']
	profile.allow_cache	= rendition['rendition'].header['allow_cache']
	profile.target_duration = rendition['rendition'].header['target_duration']
	profile.save()
	for tsfile in rendition['rendition'].files:
	    profile_file = ProfileFile()
	    profile_file.profile  = profile
	    profile_file.number   = tsfile['number']
	    profile_file.extinf   = tsfile['extinf']
	    profile_file.filename = tsfile['filename']
	    profile_file.save()

    return True
Пример #10
0
def create_or_edit_video(request, project_slug, video_slug=None):
    project = get_object_or_404(Project, slug=project_slug)
    if video_slug:
        if not project.get_perms(request.user).get("has_member_perm", False):
            request.user.message_set.create(message=NEED_MEMBER_PERM)
            
        else:
            video = get_object_or_404(Video, slug=video_slug, project=project)
            if request.method == "POST" and  "update" in request.POST:
                video.sync_with_yt()
                video.save()
                request.user.message_set.create(message="Video infromation was updated.")
            else:
                request.user.message_set.create(message="Invalid data.")
        return HttpResponseRedirect(video.get_absolute_url())
    else:
        action = "Add new Video"
        form_class = forms.VideoCreationForm
        video = Video(project=project, added_by=request.user)
    
    if request.method == 'POST':
        form = form_class(data=request.POST, instance=video)
        form.project = project
        if form.is_valid():
            video = form.save()
            return HttpResponseRedirect(video.get_absolute_url())
            
    else:
        form = form_class(instance=video)
        
    return render_to_response('projects/create_or_edit_video.html', locals(),
                               context_instance=RequestContext(request))            
Пример #11
0
    def test_model_video_url(self):
        video = Video(title="I is title",description="i is desc")
        video.video_h264 = "h264.mp4"
        video.video_webm = "webm.webm"
        video.save()

        self.assertEqual("/media/episode-%s/%s" % (video.id, "h264.mp4"), video.h264)
        self.assertEqual("/media/episode-%s/%s" % (video.id, "webm.webm"), video.webm)
Пример #12
0
    def test_video_slugify_on_save(self):
        video = Video()
        video.title = "I am an awesome title"
        video.description = "I am a description"

        video.save()

        self.assertEqual("i-am-an-awesome-title", video.slug)
Пример #13
0
def get_random_video_from_categories(categories):
    if not Video.query().filter(Video.categories.IN(categories)).get():
        return
    random_float = random.uniform(0,
                                  get_max_random_with_categories(categories))
    return Video.query(). \
        order(Video.random). \
        filter(Video.approved == True, Video.categories.IN(categories),
               Video.random >= random_float).get()
Пример #14
0
def api_user_manage_videos(*, page='1', user_id):
    page_index = get_page_index(page)
    num = yield from Video.findNumber('count(*)',
                                      where="user_id='" + user_id + "'")
    p = Page(num, page_index, 10)
    videos = yield from Video.findAll(where="user_id='" + user_id + "'",
                                      orderBy="created_at desc",
                                      limit=(p.offset, p.limit))
    return dict(videos=videos, page=p)
Пример #15
0
def scheduled_job():
    if channel_url:
        channel = Channel(channel_url)
        crawler = ChannelCrawler(youtube_service, channel)
        Video.save_or_update(crawler.crawl())
    elif playlist_url:
        playlist = Playlist(playlist_url)
        crawler = PlaylistCrawler(youtube_service, playlist)
        Video.save_or_update(crawler.crawl())
Пример #16
0
    def test_delete_video_w_wrong_token(self):
        print('Testing to Delete one Video in specific with Artist Token: ')
        video = Video(title="The Giver", type="Movie")
        video.insert()

        res = self.client().delete(
            '/videos/' + str(video.id),
            headers={"Authorization": "Bearer {}".format(self.artist)})

        self.assertEqual(res.status_code, 401)
Пример #17
0
def add_to_db(video_files):
    for video_file in video_files:
        video_filename = video_file.rsplit('/', 1)[1] # Get filename
        
        if not Video.objects.filter(filename=video_filename).exists():
            video = Video(title=os.path.splitext(video_filename)[0], \
                          filename=video_filename, \
                          fspath=video_file, \
                          media_url=MEDIA_URL + video_file.split(MEDIA_ROOT)[1])
            video.save()
            print 'Added to DB: ' + video_filename
    def setUp(self):
        """Add sample data.
        Create test client."""

        # drop the database tables and recreate them
        db.drop_all()
        db.create_all()

        user1 = User.signup("*****@*****.**", "allison", "allison", "Allison", "McAllison", None)
        user1.id = 1111

        user2 = User.signup("*****@*****.**", "jackson", "jackson", "Jackson", "McJackson", None)
        user2.id = 2222

        db.session.commit()

        self.user1 = user1
        self.user2 = user2

        # Create a course
        course1 = Course(title="Jackson's Course Title", description="Jackson's Course Description", creator_id="2222")
        db.session.add(course1)
        db.session.commit()
        self.c = course1
        self.c_id = self.c.id

        # Add two videos to the course
        video1 = Video(title="Video1", description="Desc for Video1", yt_video_id="yfoY53QXEnI", yt_channel_id="video1video1", yt_channel_title="Video1 Channel", thumb_url="https://i.ytimg.com/vi/yfoY53QXEnI/hqdefault.jpg")

        video2 = Video(title="Video2", description="Desc for Video2", yt_video_id="1PnVor36_40", yt_channel_id="video2video2", yt_channel_title="Video2 Channel", thumb_url="https://i.ytimg.com/vi/1PnVor36_40/hqdefault.jpg")

        db.session.add(video1)
        db.session.add(video2)
        db.session.commit()

        self.v1 = video1
        self.v2 = video2

        vc1 = VideoCourse(course_id=self.c.id, video_id=video1.id, video_seq=1)
        vc2 = VideoCourse(course_id=self.c.id, video_id=video2.id, video_seq=2)

        db.session.add(vc1)
        db.session.add(vc2)
        db.session.commit()      

        self.vc1 = vc1
        self.vc2 = vc2
        self.vc1_id = vc1.id
        self.vc2_id = vc2.id
        self.vc1_video_seq = self.vc1.video_seq
        self.vc2_video_seq = self.vc2.video_seq

        # set the testing client server
        self.client = app.test_client()
Пример #19
0
def import_s3(start, dv):
    s3key = start.arguments['key']
    s3bucket = start.arguments['bucket']
    logging.info("processing key  {}space".format(s3key))
    if dv is None:
        dv = Video()
        dv.name = "pending S3 import from s3://{}/{}".format(s3bucket, s3key)
        dv.save()
        start.video = dv
        start.save()
    path = "{}/{}/".format(settings.MEDIA_ROOT, start.video.pk)
    if s3key.strip() and (s3key.endswith('.zip') or s3key.endswith('.mp4')):
        fname = 'temp_' + str(time.time()).replace('.', '_') + '_' + str(random.randint(0, 100)) + '.' + \
                s3key.split('.')[-1]
        command = [
            "aws", "s3", "cp", '--quiet', "s3://{}/{}".format(s3bucket, s3key),
            fname
        ]
        path = "{}/".format(settings.MEDIA_ROOT)
        download = subprocess.Popen(args=command, cwd=path)
        download.communicate()
        download.wait()
        if download.returncode != 0:
            start.errored = True
            start.error_message = "return code for '{}' was {}".format(
                " ".join(command), download.returncode)
            start.save()
            raise ValueError, start.error_message
        handle_downloaded_file("{}/{}".format(settings.MEDIA_ROOT,
                                              fname), start.video,
                               "s3://{}/{}".format(s3bucket, s3key))
    else:
        start.video.create_directory(create_subdirs=False)
        command = [
            "aws", "s3", "cp", '--quiet',
            "s3://{}/{}/".format(s3bucket, s3key), '.', '--recursive'
        ]
        command_exec = " ".join(command)
        download = subprocess.Popen(args=command, cwd=path)
        download.communicate()
        download.wait()
        if download.returncode != 0:
            start.errored = True
            start.error_message = "return code for '{}' was {}".format(
                command_exec, download.returncode)
            start.save()
            raise ValueError, start.error_message
        with open("{}/{}/table_data.json".format(
                settings.MEDIA_ROOT, start.video.pk)) as input_json:
            video_json = json.load(input_json)
        importer = serializers.VideoImporter(video=start.video,
                                             json=video_json,
                                             root_dir=path)
        importer.import_video()
Пример #20
0
    def test_delete_video_w_token(self):
        print('Testing to Delete one Video in specific with Mod Token: ')
        video = Video(title="The Giver", type="Movie")
        video.insert()

        res = self.client().delete(
            '/videos/' + str(video.id),
            headers={"Authorization": "Bearer {}".format(self.mod)})
        data = json.loads(res.data)

        self.assertEqual(res.status_code, 200)
        self.assertTrue(data['success'])
Пример #21
0
				def cb(el):
					if 'compactVideoRenderer' in el:
						src_id = el['compactVideoRenderer']['navigationEndpoint']['watchEndpoint']['videoId']
						title = el['compactVideoRenderer']['title']['simpleText']
						print('found vid:', src_id, title)

						v = Video.query.filter_by(src='yt', src_id=src_id).first()
						if v is None:
							v = Video(src='yt', src_id=src_id)
							db.session.add(v)
						v.title = title
						db.session.commit()
Пример #22
0
def update_list(**kwargs):
    try:
        from models import Video

        user_id = get_jwt_identity()
        new_one = Video(user_id=user_id, **kwargs)
        new_one.save()
    except Exception as e:
        logger.warning(
            f'user:{user_id} tutorials - create action filed with error: {e}')
        return {'message': str(e)}, 400

    return new_one
Пример #23
0
def handle_youtube_video(name, url, extract=True, user=None, rate=30, rescale=0):
    video = Video()
    if user:
        video.uploader = user
    video.name = name
    video.url = url
    video.youtube_video = True
    video.save()
    if extract:
        p = processing.DVAPQLProcess()
        query = {
            'process_type': DVAPQL.PROCESS,
            'tasks': [
                {
                    'arguments': {'next_tasks': [
                        {'operation': 'decode_video',
                         'arguments': {
                             'rate': rate,
                             'rescale': rescale,
                             'next_tasks': settings.DEFAULT_PROCESSING_PLAN
                         }
                         }
                    ]},
                    'video_id': video.pk,
                    'operation': 'segment_video',
                }
            ]
        }
        p.create_from_json(j=query, user=user)
        p.launch()
    return video
Пример #24
0
    def test_patch_video_w_token(self):
        print('Testing to Patch one Artist in specific with Mod Token: ')
        video = Video(title="MagicMan", type="tutorial")
        video.insert()

        res = self.client().patch(
            '/videos/' + str(video.id),
            headers={"Authorization": "Bearer {}".format(self.mod)},
            json={"type": "livestream"})
        data = json.loads(res.data)

        self.assertEqual(res.status_code, 200)
        self.assertTrue(data['success'])
        self.assertEqual(data['video']['type'], 'livestream')
Пример #25
0
def video():
    if request.method == 'GET':
        return render_template('video.html')
    else:
        name = request.form.get('name')
        content = request.form.get('content')
        desc = request.form.get('desc')
        video = Video(name=name, content=content, desc=desc)
        user_id = session.get('user_id')
        user = User.query.filter(User.id == user_id).first()
        video.author = user
        db.session.add(video)
        db.session.commit()
        return redirect(url_for('index'))
Пример #26
0
def paginate():
    pagination = PaginatedQuery(Video.select().order_by(Video.id.desc()), 50)

    return 1, {
        'pre':
        50,
        'page':
        pagination.get_page(),
        'count':
        Video.select().count(),
        'data': [{
            **model_to_dict(video), 'code': None
        } for video in pagination.get_object_list()]
    }
Пример #27
0
    def process_play_complete(self, timestamp):
       next_video = None

       if self.force_play_id:
           print "force video lined up"
           next_video = Video.objects(id = self.force_play_id)   
           self.force_play_id = None

       if not next_video:
           print "get next video based on timestamp"
           next_video = Video.objects(created_at__gt=timestamp)

       if next_video:
           self.play_async(next_video[0]['video_url'], next_video[0]['created_at'])
Пример #28
0
def handle_youtube_video(name,
                         url,
                         extract=True,
                         user=None,
                         perform_scene_detection=True,
                         rate=30,
                         rescale=0):
    video = Video()
    if user:
        video.uploader = user
    video.name = name
    video.url = url
    video.youtube_video = True
    video.save()
    task_name = 'extract_frames_by_id'
    extract_frames_task = TEvent()
    extract_frames_task.video = video
    extract_frames_task.operation = task_name
    extract_frames_task.arguments_json = json.dumps({
        'perform_scene_detection': perform_scene_detection,
        'rate': rate,
        'rescale': rescale
    })
    extract_frames_task.save()
    if extract:
        app.send_task(name=task_name,
                      args=[
                          extract_frames_task.pk,
                      ],
                      queue=settings.TASK_NAMES_TO_QUEUE[task_name])
    return video
Пример #29
0
def create_query(count, approximate, selected, excluded_pks, image_data_url):
    query = Query()
    query.count = count
    if excluded_pks:
        query.excluded_index_entries_pk = [int(k) for k in excluded_pks]
    query.selected_indexers = selected
    query.approximate = approximate
    image_data = base64.decodestring(image_data_url[22:])
    if settings.HEROKU_DEPLOY:
        query.image_data = image_data
    query.save()
    dv = Video()
    dv.name = 'query_{}'.format(query.pk)
    dv.dataset = True
    dv.query = True
    dv.parent_query = query
    dv.save()
    create_video_folders(dv)
    query_path = "{}/queries/{}.png".format(settings.MEDIA_ROOT, query.pk)
    query_frame_path = "{}/{}/frames/0.png".format(settings.MEDIA_ROOT, dv.pk)
    if settings.HEROKU_DEPLOY:
        s3 = boto3.resource('s3')
        s3.Bucket(settings.MEDIA_BUCKET).put_object(Key=query_path,
                                                    Body=image_data)
        s3.Bucket(settings.MEDIA_BUCKET).put_object(Key=query_frame_path,
                                                    Body=image_data)
    else:
        with open(query_path, 'w') as fh:
            fh.write(image_data)
        with open(query_frame_path, 'w') as fh:
            fh.write(image_data)
    return query, dv
Пример #30
0
def get_playlist_videos(playlist_id):
    thumbnails, originals = create_playlist_directory(playlist_id)

    videos = []

    nextPageToken = None

    while True:

        request = youtube_service.playlistItems().list(
            part='snippet, contentDetails',
            playlistId=playlist_id,
            maxResults=50,
            pageToken=nextPageToken)

        response = request.execute()

        for item in response['items']:
            video = Video()

            video.id = item['contentDetails']['videoId']
            video.title = item['snippet']['title']

            try:
                thumbnail_url = item['snippet']['thumbnails']['default']['url']
                thumbnail_path = thumbnails + "/" + video.id + ".jpg"
                urllib.request.urlretrieve(thumbnail_url, thumbnail_path)

            except KeyError:
                thumbnail_url = None
            try:
                fullsized_url = item['snippet']['thumbnails']['maxres']['url']
                fullsized_path = originals + "/" + video.id + ".jpg"
                urllib.request.urlretrieve(fullsized_url, fullsized_path)

            except KeyError:
                fullsized_url = None

            video.thumbnail_image_url = thumbnail_url
            video.thumbnail_image_path = thumbnail_path
            video.fullsized_image_url = fullsized_url
            video.fullsized_image_path = fullsized_path

            video.url = "https://www.youtube.com/watch?v=" + item[
                'contentDetails']['videoId']

            videos.append(video)

        nextPageToken = response.get('nextPageToken')

        if not nextPageToken:
            break

    return videos
Пример #31
0
def generate_view(request):

    bilibili_url = request.GET.get('url','') 
    aid = get_aid(bilibili_url)
    
    if not aid:
        sys.exit()
    data_dict = view_data(aid)
    error = data_dict.get('error','')

    if error:
#        remove the data which have problem
        print '@253', error
        return HttpResponse('finished')

    cid,pages = data_dict['cid'],int(data_dict['pages'])

#    source_json = get_video_source(cid)
    video_list = Video.objects.filter(aid = aid)
    
    if len(video_list) == 0:
        v = Video(aid=aid)
        v.title = data_dict['title']
        v.pic_url = data_dict['pic']
        v.save()
    else:
        v = video_list[0]
    

    for i in range(1,pages+1):
        time.sleep(5)
        data_dict = view_data(aid,i)
        
        cid = data_dict['cid']
        partname = data_dict['partname']
        video_title = data_dict['title']
        video_path = video_title

        source_json = get_video_source(cid)

        title = data_dict['partname']
        if not title:
            title = data_dict['title']
        code,path = get_video(source_json,'%s' % (title))
        
        if code == 0 and path: 
            save_part(data_dict,v,path)

    return HttpResponse('finished')
Пример #32
0
def get_playlist_videos_json(playlist_title):
    query = Playlist.all()
    query.filter('title =', playlist_title)
    playlist = query.get()

    video_query = Video.all()
    video_query.filter('playlists = ', playlist_title)
    video_key_dict = Video.get_dict(video_query, lambda video: video.key())

    video_playlist_query = VideoPlaylist.all()
    video_playlist_query.filter('playlist =', playlist)
    video_playlist_query.filter('live_association =', True)
    video_playlist_key_dict = VideoPlaylist.get_key_dict(video_playlist_query)

    return json.dumps(get_playlist_video_api_dicts(playlist, video_key_dict, video_playlist_key_dict), indent=4)
Пример #33
0
def saveVideo():
    #Saving Video#
    print 'saveVideo called'
    try:
        myDB.connect()
        record = json.loads(request.data)
        #Get all the label ids here#
        labels = record['labels']
        videoId = record['videoId']
        labelArray = []
        #for k,v in sorted(label,key=itemgetter('year')):
        #    print k, v
        for record in labels:
            oneLabel = Label.select().where((Label.category == record['name'])
                               & (Label.label == record['value'])).get()
            #commaLabelIds = commaLabelIds + str(oneLabel.labelId) + ','
            labelArray.append(str(oneLabel.labelId))

        video = Video.select().where(Video.videoId == videoId).get()
        labelArray.sort()
        csvLabels = ",".join([str(x) for x in labelArray])
        video.labelIds = csvLabels   #commaLabelIds[:-1]
        video.status = 'Y'
        video.save()
        myDB.close()
    except Exception as e:
        myDB.close()
        traceback.print_exc(file=sys.stdout)
        return 'Save Video Error', 404
    return 'Video/Labels saved'
Пример #34
0
def video_title_dicts():
    return map(
        lambda video: {
            "title": video.title,
            "key": str(video.key()),
            "ka_url": "/video/%s" % video.readable_id
        }, Video.get_all_live())
Пример #35
0
def library_content_html(mobile=False, version_number=None):

    if version_number:
        version = TopicVersion.get_by_number(version_number)
    else:
        version = TopicVersion.get_default_version()

    tree = Topic.get_root(version).make_tree(types = ["Topics", "Video", "Exercise", "Url"])

    videos = [item for item in walk_children(tree) if item.kind()=="Video"]

    root, = prepare(tree)
    topics = root.subtopics

    timestamp = time.time()

    template_values = {
        'topics': topics,
        'is_mobile': mobile,
        # convert timestamp to a nice integer for the JS
        'timestamp': int(round(timestamp * 1000)),
        'version_date': str(version.made_default_on),
        'version_id': version.number,
        'approx_vid_count': Video.approx_count(),
        'exercise_count': Exercise.get_count(),
    }

    html = shared_jinja.get().render_template("library_content_template.html", **template_values)

    return html
Пример #36
0
    def post(self):

        videoBlobInfo = self.get_uploads('video')
        screenshotBlobInfo = self.get_uploads('screenshot')
        title = self.request.get("title")
        description = self.request.get("description")

        if len(videoBlobInfo) != 1 or len(
                screenshotBlobInfo) != 1 or not title or not description:
            return self.uploadError(400)
        if not users.is_current_user_admin():
            return self.uploadError(401)

        uploadRoot = self.request.host_url + BLOB_ROOT
        videoBlobKey = str(videoBlobInfo[0].key())
        videoBlobUri = uploadRoot + videoBlobKey + "/" + videoBlobInfo[
            0].filename
        screenshotBlobKey = str(screenshotBlobInfo[0].key())
        screenshotBlobUri = uploadRoot + screenshotBlobKey + "/" + screenshotBlobInfo[
            0].filename
        userId = users.get_current_user().user_id()

        userEntity = User.getById(userId)
        videoEntity = Video(id=videoBlobKey,
                            videoUri=videoBlobUri,
                            screenshotUri=screenshotBlobUri,
                            uploadUser=userId,
                            title=title,
                            description=description,
                            vector=[])
        ndb.put_multi([userEntity, videoEntity])

        self.response.headers['Content-Type'] = 'application/json'
        self.response.out.write(json.dumps({'id': videoBlobKey}))
Пример #37
0
def save_new():
    if request.method != 'POST':
        raise RequestMethodNotAllowed(
            msg="The method %s is not allowed for the requested URL" %
            request.method)
    form = VideoSaveForm()
    user = db.session.query(User).filter_by(id=g.user.uid).first()
    # if not user.cover_name_temp or not user.video_name_temp:
    #     return params_error(message="未上传视频或封面")
    if form.validate_for_api() and form.validate():
        title = form.title.data
        sign = form.sign.data
        duration = form.duration.data
        type = form.type.data
        video = Video(title=title,
                      video=user.video_name_temp,
                      cover=user.cover_name_temp,
                      sign=sign,
                      duration=duration,
                      type=type,
                      uid=user.id)
        db.session.add(video)
        db.session.commit()
        user.video_name_temp = ""
        user.cover_name_temp = ""
        db.session.commit()
        return success(message="保存视频成功")
    else:
        return params_error(message=form.get_error())
Пример #38
0
def add(channel_slug):
    data = json.loads(request.data.decode())
    id = data["id"]
    errors = []
    if len(id) != 11:
        errors.append("Add a youtube id not a link.")
        return jsonify({"error": errors})

    channel = Channel.query.filter_by(slug=channel_slug).first()
    if not channel:
        return "404 - Not found"

    # see if video exists if it doesnt make a new one
    video = Video.query.filter_by(code=id).first()
    if not video:
        url = 'http://gdata.youtube.com/feeds/api/videos/{}?alt=json&v=2'.format(
            id)
        title_data = json.loads(urllib.urlopen(url).read())
        duration = title_data['entry']['media$group']['media$content'][0][
            'duration']
        title = title_data['entry']['title']['$t']
        video = Video(id, title=title, duration=duration)
        db.session.add(video)
        db.session.commit()
    try:
        record = Record(channel.id, video.id)
        db.session.add(record)
        db.session.commit()
        return jsonify({"succes": True})
    except:
        errors.append("Unable to add item to database.")
        return jsonify({"error": errors})
Пример #39
0
def video_title_dicts():
    return map(lambda video: {
        "title": video.title,
        "key": str(video.key()),
        "ka_url": video.relative_url, # remove once js clients update
        "url": video.relative_url
    }, [v for v in Video.get_all_live() if v is not None])
Пример #40
0
 def get(self, id=1):
   video = Video.get(id)
   debug = str(video)
   render_template(self, 'video.html', {
     'video': video,
     'debug': debug,
   })
Пример #41
0
def get_content():

    youtube_id = 'ORZltL9glEA'
    r = requests.get(
        "https://www.googleapis.com/youtube/v3/videos?part=statistics&id={}%2C&key={}"
        .format(youtube_id, DEVELOPER_KEY))
    r1 = requests.get(
        "https://www.googleapis.com/youtube/v3/videos?part=snippet&id=" +
        youtube_id + "&key=" + DEVELOPER_KEY)
    data = json.loads(r.text)
    items = data['items'][0]
    data1 = json.loads(r1.text)
    items1 = data1['items'][0]
    channel_id = items1['snippet']['channelId']
    statistics = items['statistics']
    # result = Video(youtube_id, channel_id, comment_count, dislike_count, favorite_count, like_count, view_count)
    result = Video({
        'statistics': statistics,
        'youtube_id': youtube_id,
        'channel_id': channel_id
    })
    db.session.add(result)
    db.session.commit()
    print(result)

    # return jsonify({'statistics': statistics, 'youtube_id': youtube_id, 'channel_id': channel_id})
    # return {'statistics': statistics, 'youtube_id': youtube_id, 'channel_id': channel_id}
    return result
Пример #42
0
def searchVideos():
    videos = []
    #Subject.name ** ('%' + keyword + '%'),
    myDB.connect()
    try:
        record = json.loads(request.data)
        labels = record['labels']
        labelArray = []
        for record in labels:
            oneLabel = Label.select().where((Label.category == record['name'])
                               & (Label.label == record['value'])).get()
            #commaLabelIds = commaLabelIds + str(oneLabel.labelId) + ','
            labelArray.append(str(oneLabel.labelId))

        labelArray.sort()
        csvLabels = ",".join([str(x) for x in labelArray])

        #for record in Video.select().where(Video.status == 'N').get():
        for record in Video.select().where(Video.labelIds % ('%' + csvLabels + '%')):
            videos.append({'videoId':record.videoId, 'fileName':record.fileName,
                       'folderName':record.folderName, 'boxLink':record.boxLink})
        #print videos
    except Exception as e:
        myDB.close()
        print e
        return 'Search Videos Error', 404
    if len(videos) == 0:
        return 'No Videos'
    return jsonify(data=videos)
Пример #43
0
def get_video_library_json_compressed():
    playlist_api_dicts = []
    playlists = get_all_topic_playlists()
    video_key_dict = Video.get_dict(Video.all(), lambda video: video.key())

    video_playlist_query = VideoPlaylist.all()
    video_playlist_query.filter('live_association =', True)
    video_playlist_key_dict = VideoPlaylist.get_key_dict(video_playlist_query)

    for playlist in playlists:
        playlist_api_dict = JsonApiDict.playlist(playlist)
        playlist_api_dict["videos"] = get_playlist_video_api_dicts(playlist, video_key_dict, video_playlist_key_dict)
        playlist_api_dicts.append(playlist_api_dict)

    # We compress this huge json payload so it'll fit in memcache
    return zlib.compress(json.dumps(playlist_api_dicts, indent=4))
Пример #44
0
def video_title_dicts():
    live_video_dict = {}
    for video_playlist in VideoPlaylist.all().filter('live_association = ', True):
        live_video_dict[VideoPlaylist.video.get_value_for_datastore(video_playlist)] = True

    live_videos = filter(lambda video: video.key() in live_video_dict, Video.all())
    return map(lambda video: {"title": video.title, "url": "/video/%s" % video.readable_id}, live_videos)
Пример #45
0
    def setUp(self):
        """Add sample data.
        Create test client."""

        db.drop_all()
        db.create_all()

        user1 = User.signup("*****@*****.**", "allison", "allison", "Allison", "McAllison", None)
        user1.id = 1111

        user2 = User.signup("*****@*****.**", "jackson", "jackson", "Jackson", "McJackson", None)
        user2.id = 2222

        v = Video(title="Title of a YouTube Video", description="Description of a YouTube Video", yt_video_id="yfoY53QXEnI", yt_channel_id="UC29ju8bIPH5as8OGnQzwJyA")

        c = Course(title = "This course title is a test", description = "This course description is a test", creator_id = user1.id)

        db.session.add(v)
        db.session.add(c)
        db.session.commit()

        self.user1 = user1
        self.user2 = user2
        self.v = v
        self.c = c

        # set the testing client server
        self.client = app.test_client()
Пример #46
0
 def get(self):
     self.render_jinja2_template(
         'about/getting_started.html', {
             "selected_id": "getting-started",
             "approx_vid_count": Video.approx_count(),
             "App": App
         })
Пример #47
0
Файл: app.py Проект: gamerlv/mmq
def add(channel_slug):
    data = json.loads(request.data)
    id = data["id"]
    errors = []
    if len(id) != 11:
        errors.append("Add a youtube id not a link.")
        return jsonify({"error": errors})

    channel = Channel.query.filter_by(slug=channel_slug).first()
    if not channel:
        return "404 - Not found"
    # see if video exists if it doesnt make a new one
    video = Video.query.filter_by(code=id).first()
    if not video:
        title = data["title"]
        duration = data["duration"]
        video = Video(id, title=title, duration=duration)
        db.session.add(video)
        db.session.commit()
    try:
        record = Record(channel.id, video.id)
        db.session.add(record)
        db.session.commit()
        return jsonify({"succes": True})
    except:
        errors.append("Unable to add item to database.")
        return jsonify({"error": errors})
Пример #48
0
def home():
    if _('CLOSEUI') == 'YES':
        return 'Hello Free-HLS!'

    total_tags = Tag.select().count()
    total_videos = Video.select().count()
    latest_tags = {
        vtag.tag.id: vtag.tag
        for vtag in VideoTag.select().join(Tag).order_by(
            VideoTag.id.desc()).group_by(VideoTag.tag).limit(10)
    }
    video_tags = VideoTag.select().join(Tag).switch(VideoTag).join(
        Video).where(VideoTag.tag << list(latest_tags)).order_by(
            VideoTag.id.desc()).limit(50)

    tags_videos = {}
    for vt in video_tags:
        if vt.tag.id not in tags_videos:
            tags_videos[vt.tag.id] = []
        tags_videos[vt.tag.id].append(vt.video)

    return render_template('home.html',
                           total_tags=total_tags,
                           total_videos=total_videos,
                           latest_tags=latest_tags,
                           tags_videos=tags_videos)
Пример #49
0
 def test_derive_key_name_from_video(self):
     self._set_responses_xrange(BATCH_SIZE)
     _task_handler('UUID')
     videos = Video.all().fetch(BATCH_SIZE)
     for v in videos:
         key = VideoSubtitles.get_key_name('en', v.youtube_id)
         subs = VideoSubtitles.get_by_key_name(key)
         self.assertIsNotNone(subs)
Пример #50
0
 def post(self, id):
   video = Video.get(id)
   
   author = cgi.escape(self.request.get('author'))
   text = cgi.escape(self.request.get('text'))
   
   comment = Comment(video=video, author=author, text=text)
   comment.save()
   self.redirect('/video/%s' % id)
Пример #51
0
def cm_PostCuePoint(request):
    if request.method == 'GET':
        return TemplateResponse(request, 'cue_manager.html')

    if request.method != 'POST':
        status = http_METHOD_NOT_ALLOWED
        return HttpResponse('', status=status)

    if 'house_id' in request.POST.keys():
        house_id = request.POST['house_id']
    else:
       status = http_BAD_REQUEST
       return HttpResponse('', status=status)

    if house_id == '':
        status = http_BAD_REQUEST
        return HttpResponse('', status=status)

    languages = Language.objects.all()

    for key, value  in request.POST.iteritems():
        if key.endswith('_tc') and value != '':
            i, t = key.split('_')
            for lang in languages:
                lang_key = '%s_%s' % (i, lang.code)
                if lang_key in request.POST.keys() and request.POST[lang_key] != '':
                    try:
                        video = Video.objects.get(house_id = house_id)
                    except:
                        video = Video()
                        video.house_id = house_id
                        video.save()
                    cuepoint          = CuePoint()
                    cuepoint.video    = video
                    cuepoint.timecode = value
                    cuepoint.language = lang
                    cuepoint.name     = request.POST[lang_key]
                    cuepoint.save()

    status = http_POST_OK
    return TemplateResponse(request, 'cue_manager.html')
Пример #52
0
def _process_fullcopy(key):

    # Set the content-type correctly
    bucket = helper.get_bucket()
    k = bucket.lookup(key)
    k.copy(k.bucket, k.name, preserve_acl=True, metadata={'Content-Type': helper.get_mimetype(k.name)})

    orig_video = Video(key=key, status='downloading')
    db.add(orig_video)
    db.commit()
    url = helper.get_s3url(key)
    orig_path = download_url(url)

    orig_video.update(get_video_attrs(orig_path))
    orig_video.status = 'done'

    for preset in FFMPEG_PRESETS.iterkeys():

        # Transcode/Upload based on ffmpeg preset
        iphone_path = os.path.splitext(orig_path)[0] + preset
        iphone_video = Video(key=os.path.basename(iphone_path), status='transcoding')
        db.add(iphone_video)
        db.commit()

        try:
            make_iphone(orig_path, iphone_path, preset)
            iphone_video.update(get_video_attrs(iphone_path))
        except:
            iphone_video.status = 'transcoding error'
        else:
            iphone_video.status = 'uploading'

        db.commit()

        if iphone_video.status == 'uploading':
            upload_to_s3(iphone_path)
            iphone_video.status = 'done'
            db.commit()
            os.remove(iphone_path)

    os.remove(orig_path)
Пример #53
0
def video_title_dicts(version_number=None):
    if version_number:
        version = TopicVersion.get_by_number(version_number)
    else:
        version = None

    return [{
        "title": video.title,
        "key": str(video.key()),
        "relative_url": "/video/%s" % video.readable_id,
        "id": video.readable_id
    } for video in Video.get_all_live(version=version) if video is not None]
Пример #54
0
 def save_to_db(self):
     session = get_session()
     try:
         video_topic = \
             session.query(VideoTopic).filter(VideoTopic.henhen_id
                 == self.qvod_id).first()
         index_order = 0
         for img in self.imgs:
             video_img = VideoImg()
             video_img.pic_order = index_order
             video_img.url = img
             video_img.video_topic_id = video_topic.id
             index_order = index_order + 1
             session.add(video_img)
         video = Video()
         video.video_topic_id = video_topic.id
         video.url = self.qvod_address
         session.add(video)
         session.commit()
     finally:
         session.close()
Пример #55
0
 def process_play(self, video_id):
     print "process play"
     item = Video.objects(id = video_id)
     if not item:
         return
     print item.to_json()
     if self.sub:
         self.force_play_id = video_id
         self.process_cmd("EXIT")
     else:
         self.play_async(item[0]['video_url'], item[0]['created_at'])
     print "process play completed"
Пример #56
0
def add_video(request):
    err = check_arguments(request, ["videoID"])
    if err: return err

    videoID = request.POST["videoID"]

    # check to see if video exists for user
    # TODO refactor to use get_video_query
    if Video.objects.filter(user=request.user, videoID=videoID).count() != 0:
        return HttpResponse(status=409, content="videoID %s already exists for user" % videoID)

    # look up video in youtube api
    from gdata.youtube.service import YouTubeService
    yt_service = YouTubeService()
    data = yt_service.GetYouTubeVideoEntry(video_id=videoID)

    # save new video for user
    v = Video(videoID=videoID, user=request.user, title=data.media.title.text)
    v.save()

    return HttpResponse(status=201, content=json.dumps(v.render()))
Пример #57
0
def import_vdn_dataset_url(server, url, user):
    r = requests.get(url)
    response = r.json()
    vdn_dataset = create_dataset(response, server)
    vdn_dataset.save()
    video = Video()
    if user:
        video.uploader = user
    video.name = vdn_dataset.name
    video.vdn_dataset = vdn_dataset
    video.save()
    if vdn_dataset.download_url:
        task_name = 'import_vdn_file'
        import_video_task = TEvent()
        import_video_task.video = video
        import_video_task.operation = task_name
        import_video_task.save()
        app.send_task(name=task_name, args=[import_video_task.pk, ], queue=settings.TASK_NAMES_TO_QUEUE[task_name])
    elif vdn_dataset.aws_key and vdn_dataset.aws_bucket:
        task_name = 'import_vdn_s3'
        import_video_task = TEvent()
        import_video_task.video = video
        import_video_task.operation = task_name
        import_video_task.save()
        app.send_task(name=task_name, args=[import_video_task.pk, ], queue=settings.TASK_NAMES_TO_QUEUE[task_name])
    else:
        raise NotImplementedError
Пример #58
0
 def updateVideoAndPlaylistReadableNames(self):
     # Makes sure every video and playlist has a unique "name" that can be used in URLs
     query = Video.all()
     all_videos = query.fetch(100000)
     for video in all_videos:
         potential_id = re.sub('[^a-z0-9]', '-', video.title.lower());
         potential_id = re.sub('-+$', '', potential_id)  # remove any trailing dashes (see issue 1140)
         potential_id = re.sub('^-+', '', potential_id)  # remove any leading dashes (see issue 1526)                        
         if video.readable_id == potential_id: # id is unchanged
             continue
         number_to_add = 0
         current_id = potential_id
         while True:
             query = Video.all()
             query.filter('readable_id=', current_id)
             if (query.get() is None): #id is unique so use it and break out
                 video.readable_id = current_id
                 video.put()
                 break
             else: # id is not unique so will have to go through loop again
                 number_to_add+=1
                 current_id = potential_id+'-'+number_to_add                       
Пример #59
0
def getVideos():
    #Sending Videos#
    #input = {"result":"OK", "videos": [
    #    { "videoId":"1" , "fileName":"abc.mp4", "boxLink":"https://box.com/s/abc.mp4", "folderName":"Game234" },
    #    { "videoId":"2" , "fileName":"abc2.mp4", "boxLink":"https://box.com/s/abc2.mp4", "folderName":"Game234" },
    #    { "videoId":"3" , "fileName":"abc3.mp4", "boxLink":"https://box.com/s/abc3.mp4", "folderName":"Game23" }
    #]}
    #return json.dumps(input)

    #Check if there are any files with not DONE status
    #If so, return those file details
    print 'getVideos called'
    videos = []
    videosInDb = 'True'
    myDB.connect()

    try:
        #for record in Video.select().where(Video.status == 'N').get():
        for record in Video.raw("select * from vm_videos where status='N'"):
            videos.append({'videoId':record.videoId, 'fileName':record.fileName,
                       'folderName':record.folderName, 'boxLink':record.boxLink})
        #print videos
        if len(videos) > 0:
            print str(videos)
            responseJson = {'result':'OK', 'videos':videos}
            #return jsonify(results = videos)
            return jsonify(results = responseJson)
    except Video.DoesNotExist:
        videosInDb = 'False'

    """api_response = getBoxFolder('1311201105')
    #If no files in the table, get it from Box
    items = api_response.json['item_collection']
    filesResponse = []
    for record in items['entries']:
        folderId = record['id']
        count = Video.select().where(Video.folderId == folderId).count()
        if count >= 1:
            continue
        else:
            #Call file API, insert them into Videos table and return those details
            files = getBoxFolder(folderId)
            fileItems = files.json['item_collection']['entries']
            for rs in fileItems:
                print rs['name']
                print rs['id']
            filesResponse.append(fileItems)
            return jsonify(results=filesResponse)
    """
    myDB.close()
    return 'No New Videos'
Пример #60
0
def UserUploadView(request):
    if request.user.is_authenticated():
        if request.method == "GET":
            return render_to_response('userUpload.html', None,
                                      context_instance=RequestContext(request))
        elif request.method == "POST":
            videoName = request.POST['videoName']
            vUrl = None
            if request.POST['ch'] == "own":
                handle_uploadVideo(request.FILES['videoFile'])
                vUrl = request.FILES['videoFile'].name
            elif request.POST['ch'] == "stream":
                vUrl = request.POST['videoStream']
            vLanguage = request.POST['language']
            vCategory = request.POST['category']
            pic = None
            if 'pic' not in request.FILES:
                pic = "testVideo1-12442143145e53.jpg"
            else:
                handle_uploadVideoImage(request.FILES['pic'])
                pic = request.FILES['pic'].name

            lan = Language.objects.get(pk=int(vLanguage))
            cat = Category.objects.get(pk=int(vCategory))

            video = Video(title=videoName, url="http://127.0.0.1:8000/media/" + vUrl, length=500, owner=request.user, displayImage=pic,
                          language=lan, category=cat)
            video.save()

            tags = request.POST['tags'].split(",")
            for tag in tags:
                tg, created = Tag.objects.get_or_create(tag_name=tag)
                video.video_link.add(tg)
            video.save()
            return redirect("/video/?vId=" + str(video.id))
    else:
        return render_to_response('login.html', None,
                                  context_instance=RequestContext(request))