def admin(): if request.method == "GET": videos = Video.objects() return render_template('admin.html', videos = videos) elif request.method == "POST": form = request.form link = form['link'] ydl = YoutubeDL() data = ydl.extract_info(link, download = False) title = data['title'] thumbnail = data['thumbnail'] views = data ['view_count'] youtube_id = data['id'] video = Video(title = title, thumbnail = thumbnail, views = views, youtube_id = youtube_id, link = link) video.save() return redirect(url_for("admin"))
def get(self): stories=Story.all().order('-timestamp').fetch(1000, offset=0) for story in stories: story.delete() videos=Video.all().order('-timestamp').fetch(1000, offset=0) for video in videos: video.delete()
def insert_video_info_into_db(self): title = self.web_driver.find_element_by_css_selector("h1.title").text user_container = self.web_driver.find_element_by_tag_name( "ytd-video-owner-renderer").text channel_name = user_container.split("\n")[0].strip() url = self.web_driver.current_url Video(title, channel_name, url, COMMENT, datetime.now()).insert()
def __get_video(self, item_tag): root_index = 'http://www.soku.com' video = Video() video.set_classify_1(self.__video_classify) # 获取title标签 self.__parse_title(video, item_tag) logging.info('视频名称: %s', video.get_name()) if video.get_name() in self.__video_set: logging.info('视频 %s 已经存在', video.get_name()) return None else: self.__video_set.add(video.get_name()) # 获取评分标签 self.__parse_score(video, item_tag) # 获取播放源 self.__parse_source_and_link(video, item_tag) # 获取缩略图 self.__parse_picture_url(video, item_tag) # # 获取剧集标签 self.__parse_drama_num(video, item_tag) # 获取详细链接 detail_link_tag = item_tag.find('li', 'p_link') detail_url = root_index + detail_link_tag.a.attrs.get('href') detail_html = requests.get(detail_url) soup = bs4.BeautifulSoup(detail_html.text, 'html.parser') self.__parse_detail(video, soup) return video
def admin(): if 'logged_in' in session: if request.method == 'GET': all_video = Video.objects() return render_template('admin.html', all_video=all_video) elif request.method == 'POST': form = request.form link = form['link'] ydl = YoutubeDL() data = ydl.extract_info(link, download=False) new_video = Video(title=data['title'], thumbnail=data['thumbnail'], view=data['view_count'], youtubeid=data['id']) new_video.save() return redirect(url_for('admin')) else: return "Đi chỗ khác chơi"
def post(self): link = self.get_argument('link', '') try: video = VideoM.get(VideoM.id == 1) video.link = link video.update_time = int(time()) video.save() except VideoM.DoesNotExist as e: VideoM(link=link).save() self.finish()
def admin(): if request.method == 'GET': if "logged_in" in session: videos = Video.objects() return render_template('admin.html', videos=videos) else: return render_template("error.html") elif request.method == 'POST': form = request.form link = form['link'] data = ydl.extract_info(link, download=False) title = data['title'] thumbnail = data['thumbnail'] views = data['view_count'] youtubeid = data['id'] new_video = Video(title=title, thumbnail=thumbnail, views=views, link=link, youtubeid=youtubeid) new_video.save() return redirect(url_for('admin'))
def get(self): stories=[] for s in Story.all().order('-timestamp').fetch(100): stories.append(s) videos=[] for v in Video.all().order('-timestamp').fetch(100): videos.append(v) template_values = { "stories":stories, "videos":videos } path = os.path.join(os.path.dirname(__file__), '../html/index.html') shared.render(self, path, template_values)
def upload(): if request.method == 'POST': file = request.files['file'] if file: filename = secure_filename(file.filename) filename = util.video.get_non_conflict_name(filename, current_user) mimetype = file.content_type if not util.video.allowed_file(filename): result = util.video.UploadResponse(name=filename, type=mimetype, size=0, not_allowed_msg="Filetype not allowed") else: # save then record to db video = Video.upload(file, filename, current_user) # create thumbnail after saving # if mimetype.startswith('image'): # create_thumbnai(filename) # return json for js call back result = util.video.UploadResponse(name=video.title, type=mimetype, size=video.size, not_allowed_msg=None, url=url_for('video.play', id=video.id), delete_url=url_for('video.delete', id=video.id)) # for validation return simplejson.dumps({"files": [result.get_file()]}) if request.method == 'GET': return get_current_videos() redirect(url_for('video.manage'))
def parseInputs(): script, filename = argv txt = open(filename) lines = txt.read().split('\n') first_line = lines[0] (no_videos, no_endpoints, no_requests, no_caches, cache_size) = intTuple(first_line) video_size = intTuple(lines[1]) debug("Video %d" % no_videos) debug("Videos size : ") debug(video_size) videos = [] for i in range(no_videos): videos.append(Video(i, video_size[i])) debug(videos) caches = [] for i in range(no_caches): caches.append(Cache(i, cache_size, [])) debug(caches) idx = 2 # loop endpoint endpoints = [] endpoint_id = 0 while (no_endpoints > 0): (latency_to_dc, no_caches) = intTuple(lines[idx]) idx = idx + 1 latency_to_caches = dict() for i in range(no_caches): (cache_server, latency) = intTuple(lines[idx]) latency_to_caches[cache_server] = latency idx = idx + 1 en = Endpoint(endpoint_id, latency_to_caches, latency_to_dc) endpoints.append(en) endpoint_id = endpoint_id + 1 no_endpoints = no_endpoints - 1 debug(endpoints) requests = [] while (no_requests > 0): (video_id, endpoint_id, reqs) = intTuple(lines[idx]) requests.append(Request(video_id, endpoint_id, reqs)) idx = idx + 1 no_requests = no_requests - 1 debug(requests) idx = 2 return (caches, endpoints, requests, videos)
def index(): all_video = Video.objects() return render_template('index.html', all_video=all_video)
def doCron(videos): raw_data = http.getHttp("https://gdata.youtube.com/feeds/api/standardfeeds/on_the_web") soup = BeautifulSoup(raw_data, selfClosingTags=['category']) entries=soup.findAll('entry') for entry in entries: if len(entry('title'))>0: mykey=entry('title')[0].text if len(entry('title'))>0 else None if mykey and not getVideo(videos, mykey): video=Video() video.title=entry('title')[0].text video.mykey=mykey video.text=entry('content')[0].text if len(entry('content'))>0 else '' links=entry(lambda tag: tag.name=='link' and tag.attrs[2][0]=='href' and '/watch?' in tag.attrs[2][1]) if len(links)==0: continue video.link=links[0].attrs[2][1] imgs=entry('media:thumbnail', height="90", width="120") if len(imgs)==0: continue video.img=imgs[0].attrs[0][1] imgsBig=entry('media:thumbnail', height='360', width='480') if len(imgsBig)==0: continue video.imgBig=imgsBig[0].attrs[0][1] video.tags=getTags(entry) video.categories=getCategories(entry) video.save();
def get(self): stories=Story.all().fetch(1000) GTrendCron.doCron(stories) videos=Video.all().fetch(1000) YTrendCron.doCron(videos)
def index(): Video.hottest() Video.newest() return render_template('index.html')
def index(): hottest = Video.hottest() newest = Video.newuploaded() return render_template('index.html', hottestvideos = hottest, newestvideos = newest)
def add_video(title, youtube_url, date, subcategory_id): video = Video(title, youtube_url, date, subcategory_id) insert(video)
def delete(id): Video.from_id(id).delete() return get_current_videos()
def play(id): video = Video.from_id(id) poster = User.from_id(video.poster_id) return render_template('video/play.html', poster=poster, video=video)
def index(): videos = Video.objects() return render_template('index.html', videos=videos)
def _init_video(self): w_videos = [] w_video = Video() w_video.id("45reasons") w_video.name("45 Reasons") w_video.music("45reasons") w_video.url("https://www.youtube.com/embed/9BNABYtjLR4") w_videos.append(w_video) w_video = Video() w_video.id("epicstringbattleforwhisky") w_video.name("Epic String Battle for Whisky") w_video.url("https://www.youtube.com/embed/fFMl31hB4NU") w_videos.append(w_video) w_video = Video() w_video.id("injusticeforall") w_video.name("Injustice for All") w_video.music("injusticeforall") w_video.url("https://www.youtube.com/embed/_vcxsC_r3pA") w_videos.append(w_video) w_video = Video() w_video.id("endoftime") w_video.name("End of Time") w_video.music("endoftime") w_video.url("https://www.youtube.com/embed/qBnd0j6rItY") w_videos.append(w_video) w_video = Video() w_video.id("brokenlegspart2") w_video.name("Broken Legs Pt.2") w_video.music("brokenlegspart2") w_video.url("https://www.youtube.com/embed/LGiwYy-7nJQ") w_videos.append(w_video) w_video = Video() w_video.id("thearrival") w_video.name("The Arrival") w_video.music("thearrival") w_video.url("https://www.youtube.com/embed/dMChbNTV_rg") w_videos.append(w_video) w_video = Video() w_video.id("coverocean") w_video.name("Cover Ocean") w_video.url("https://www.youtube.com/embed/Rgz36SCXfLA") w_videos.append(w_video) w_video = Video() w_video.id("covertrain") w_video.name("Cover Train") w_video.url("https://www.youtube.com/embed/JiWLMsMgKgY") w_videos.append(w_video) w_video = Video() w_video.id("coverdarrycowlchamber") w_video.name("Cover Darry Cowl Chamber") w_video.url("https://www.youtube.com/embed/QH2mjk7jt30") w_videos.append(w_video) w_video = Video() w_video.id("mindcontrol") w_video.name("Mind Control") w_video.url("https://www.youtube.com/embed/3FM8urVV4WM") w_videos.append(w_video) w_video = Video() w_video.id("aceofspades") w_video.name("Ace of Spades") w_video.url("https://www.youtube.com/embed/QDig_XMT1a8") w_videos.append(w_video) w_video = Video() w_video.id("teaseryblues") w_video.name("Teaser") w_video.url("https://www.youtube.com/embed/X8nXyU7ziss") w_videos.append(w_video) self._manager_video.up_sert_many(w_videos)