def get(self, file_id): client = self.get_authorized_client() if not client: return self.redirect('/auth-evernote?next={0}'.format(self.request.path)) try: file = self.get_file(file_id) except webapp2.HTTPException as http_ex: if http_ex.code == 401: return self.redirect('/auth?next={0}'.format(self.request.path)) base_url = self.request.host_url + '/edit/{0}'.format(file['id']) extension_loaded = bool(int(self.request.get('extensionLoaded', 1))) # Look for the VideoNot.es Notebook notestore = client.get_note_store() notesbooks = notestore.listNotebooks() notebook = None for a_notesbook in notesbooks: if a_notesbook.name == 'VideoNot.es': notebook = a_notesbook break if not notebook: notebook = Notebook() notebook.name = 'VideoNot.es' notebook = notestore.createNotebook(notebook) # Formatting the note in ENML content_enml = FileUtils.to_ENML(file, base_url) content_enml.append('<br></br><br></br>') content_enml.append('<a href="{0}">View in VideoNot.es</a>'.format(base_url)) if not extension_loaded: content_enml.append('<br/>') content_enml.append('(Tip: you can add snapshots of the video to your export by installing our <a href="https://chrome.google.com/webstore/detail/kmbcnighpdagelfjmlbakfnciogcelgi">Chrome Extension</a>)') # Saving the note in Evernote note = Note() note.title = file['title'] note_content = ''.join(content_enml).encode('utf-8') note.content = '<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd"><en-note>{0}</en-note>'.format(note_content) note.content = note.content.replace('&', '&') if notebook: note.notebookGuid = notebook.guid note = notestore.createNote(note) logging.debug('VideoNot.es %s exported to Evernote: %s', file_id, note_content) logging.info('VideoNot.es %s exported to Evernote with id: %s', file_id, note.guid) # Returning to the new note in Evernote user_store = client.get_user_store() notestore_url = '/'.join(user_store.getNoteStoreUrl().split('/')[0:5]) return self.redirect(notestore_url + '/view/notebook/{0}'.format(note.guid))
def test_to_enml_with_screenshots(self): file = { 'id': 'test', 'content': 'test' + '\n' + '<{0}>'.format(FileUtils.SNAPSHOT_KEY), 'videos': { 'video1': { 2: { 'time': 0, 'snapshot': None }, 1: { 'time': 0, 'snapshot': 'snapshot' } }, 'video2': { 0: { 'time': 0, 'snapshot': None }, 3: { 'time': 0, 'snapshot': None } } } } base_url = 'http://test.videonot.es/edit/' + file['id'] expected_enml = [ '<a href="{0}?l=1">+</a> test'.format(base_url), '<br></br>', '<br></br>', '<img src="{0}"></img>'.format('snapshot'), '<br></br>', '<a href="{0}">{0}</a>'.format('video1'), '<br></br><br></br>' ] content_enml = FileUtils.to_ENML(file, base_url) self.assertEqual(expected_enml, content_enml)
def test_to_enml_with_screenshots_youtube(self): file = { 'id': 'test', 'content': 'test' + '\n' + '<{0}>'.format(FileUtils.SNAPSHOT_KEY), 'videos': { 'http://www.youtube.com/watch?v=abc': { 2: { 'time': 0, 'snapshot': None }, 1: { 'time': 15, 'snapshot': 'snapshot' } }, 'http://www.youtube.com/watch?v=acbd': { 0: { 'time': 0, 'snapshot': None }, 3: { 'time': 0, 'snapshot': None } } } } base_url = 'http://test.videonot.es/edit/' + file['id'] expected_enml = [ '<a href="{0}?l=1">+</a> test'.format(base_url), '<br></br>', '<br></br>', '<img src="{0}"></img>'.format('snapshot'), '<br></br>', '<a href="{0}">{0}</a>'.format('http://youtu.be/abc?t=15s'), '<br></br><br></br>' ] content_enml = FileUtils.to_ENML(file, base_url) self.assertEqual(expected_enml, content_enml)
def test_to_enml_without_screenshots(self): file = { 'id': 'test', 'content': 'test' + '\n' + 'test2', 'videos': { 'video1': { 2: { 'time': 0, 'snapshot': None }, 1: { 'time': 0, 'snapshot': None } }, 'video2': { 0: { 'time': 0, 'snapshot': None }, 3: { 'time': 0, 'snapshot': None } } } } base_url = 'http://test.videonot.es/edit/' + file['id'] expected_enml = [ '<a href="{0}?l=1">+</a> test'.format(base_url), '<br></br>', '<a href="{0}?l=2">+</a> test2'.format(base_url), '<br></br>', ] content_enml = FileUtils.to_ENML(file, base_url) self.assertEqual(expected_enml, content_enml)