def clean_video_url(self): video_url = self.cleaned_data['video_url'] if not blip.BLIP_REGEX.match(video_url) and \ not vimeo.VIMEO_REGEX.match(video_url) and \ not DAILYMOTION_REGEX.match(video_url) and \ not ('youtube.com' in video_url and get_video_id(video_url)) and \ not self.URL_REGEX.match(video_url): raise forms.ValidationError(mark_safe(_(u"""Universal Subtitles does not support that website or video format. If you'd like to us to add support for a new site or format, or if you think there's been some mistake, <a href="mailto:%s">contact us</a>!""") % settings.FEEDBACK_EMAIL)) return video_url
def video(user, id): """ Show a video. """ video = get_video(id) video.id = get_video_id(video.link) if getattr(video, 'yt_duration'): video.duration = datetime.timedelta( seconds=int(video.yt_duration.get('seconds', 0))) next = get_random_video() return render_template('video.html', video=video, next=next)
def store_video(video): """ Store a video in a redis set. """ # get the video id from the URL # there are other ways, but this always works vid = get_video_id(video.link) # save the username and video id as a key-value pair # in our set, so we have both available later uid = '%s:%s' % (video.author, vid) # save the uid to our redis set # printing the video title if it's added to the set if redis.sadd(key(), uid): log.info(video.title)
def playlist_add(): if request.method == 'POST': if request.files: fp = request.files['media_file'] if fp: if allowed_file(fp.filename): filename = secure_filename('%d-%s.%s' % (time.time(), randint(1000, 999999), fp.filename)) filepath = os.path.join(app.config['UPLOAD_FOLDER'], filename) fp.save(filepath) # saved file, now try to get the uploaded info audio_file = auto.File(filepath) return render_template('playlist/confirm_upload.html', uri=filepath, song_title=audio_file.title, artist=audio_file.artist ) else: err = '%s and %s' % (', '.join(ALLOWED_EXTENSIONS[:-1]), ALLOWED_EXTENSIONS[-1]) flash(err, 'error') return else: search_term = request.form['search'] is_yt = yt_re.search(search_term) uri = title = artist = None if is_yt: video_id = get_video_id(search_term) title, artist = get_video_info(video_id) if artist is None: title, artist = title_splitter(title) else: title, artist = get_from_echonest(search_term) if not title: title = search_term.capitalize() if not artist: artist = 'Unknown' return render_template('playlist/confirm_upload.html', uri=search_term, song_title=title, artist=artist ) return render_template('playlist/add.html')
def test_get_video_id(self): for item in self.data: self.failUnlessEqual(item['video_id'], get_video_id(item['url']))
def test_get_video_id(self): for item in self.data: self.failUnlessEqual(item["video_id"], get_video_id(item["url"]))
def get_or_create_for_url(cls, video_url): parsed_url = urlparse(video_url) if 'youtube.com' in parsed_url.netloc: yt_video_id = get_video_id(video_url) video, created = Video.objects.get_or_create( youtube_videoid=yt_video_id, defaults={'video_type': VIDEO_TYPE_YOUTUBE, 'allow_community_edits': True}) if created: entry = yt_service.GetYouTubeVideoEntry(video_id=video.youtube_videoid) video.title = entry.media.title.text video.duration = entry.media.duration.seconds if entry.media.thumbnail: video.thumbnail = entry.media.thumbnail[-1].url video.save() video._get_subtitles_from_youtube() elif 'blip.tv' in parsed_url.netloc and blip.BLIP_REGEX.match(video_url): bliptv_fileid = blip.BLIP_REGEX.match(video_url).groupdict()['file_id'] video, created = Video.objects.get_or_create( bliptv_fileid=bliptv_fileid, defaults={'video_type': VIDEO_TYPE_BLIPTV, 'allow_community_edits': True}) if created: video.title = blip.scrape_title(video_url) video.bliptv_flv_url = videos_blip.scrape_best_file_url(video_url) video.video_url = video.bliptv_flv_url video.thumbnail = blip.get_thumbnail_url(video_url) video.save() elif 'video.google.com' in parsed_url.netloc and google_video.GOOGLE_VIDEO_REGEX.match(video_url): video, created = Video.objects.get_or_create( video_url=video_url, defaults={'video_type': VIDEO_TYPE_GOOGLE, 'allow_community_edits': True}) if created: video.title = google_video.scrape_title(video_url) video.save() elif 'ustream.tv' in parsed_url.netloc and ustream.USTREAM_REGEX.match(video_url): video, created = Video.objects.get_or_create( video_url=ustream.get_flash_enclosure_url(video_url), defaults={'video_type': VIDEO_TYPE_USTREAM, 'allow_community_edits': True}) if created: video.title = ustream.get_title(video_url) video.thumbnail = ustream.get_thumbnail_url(video_url) video.save() elif 'vimeo.com' in parsed_url.netloc and vimeo.VIMEO_REGEX.match(video_url): vimeo_videoid = vimeo.VIMEO_REGEX.match(video_url).group(2) video, created = Video.objects.get_or_create( vimeo_videoid = vimeo_videoid, defaults={'video_type': VIDEO_TYPE_VIMEO, 'allow_community_edits': True}) # TODO: title and thumbnail -- we can't get them without # an application oauth key/secret elif 'dailymotion.com' in parsed_url.netloc and dailymotion.DAILYMOTION_REGEX.match(video_url): metadata = dailymotion.get_metadata(video_url) stream_flv_mini_url = metadata.get('stream_flv_mini_url', '') if stream_flv_mini_url and stream_flv_mini_url != '': dailymotion_videoid = dailymotion.get_video_id(video_url) video, created = Video.objects.get_or_create( dailymotion_videoid = dailymotion_videoid, defaults={'video_type': VIDEO_TYPE_DAILYMOTION, 'allow_community_edits': True}) if created: video.title = metadata.get('title') or dailymotion_videoid video.thumbnail = metadata.get('thumbnail_url') or '' video.save() else: # not hosted by dailymotion and uses a different player # TODO: error message / specific exception type? raise Exception("dailymotion video actually hosted by partner -- we can't handle this") elif FLV_REGEX.match(video_url): video, created = Video.objects.get_or_create( video_url=video_url, defaults={'video_type': VIDEO_TYPE_FLV, 'allow_community_edits': True}) else: video, created = Video.objects.get_or_create( video_url=video_url, defaults={'video_type': VIDEO_TYPE_HTML5, 'allow_community_edits': True}) return video, created
def clean_video_url(self): video_url = self.cleaned_data["video_url"] if "youtube.com" in video_url and not get_video_id(video_url): raise forms.ValidationError(_(u"Incorrect video url")) return video_url