Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[12.0][BR000275][MIG] Migrate website_slides_qq_video from 8.0 to 12.0 #247

Open
wants to merge 6 commits into
base: 12.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions website_slides_qq_video/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3

==============================
Website Slides upload QQ video
==============================

This model extends the functionality of website_slides and allows to publish the QQ video
in the channel

Usage
=====

To use this module, you need to:

Url format is : <address>?vid=<vid>,
The vid is the key for video.

You can get it when you click any qq video most of the time, etc:
http://v.qq.com/cover/k/kg0cy3syh1ovu9z.html?vid=a001986fc2v,

But if you can't find the vid in the url, like:
http://v.qq.com/boke/page/n/0/o/n0163mjor1o.html

Click the share button under the video and find the iframe code for the video like:
<iframe frameborder="0" width="640" height="498" src="http://v.qq.com/iframe/player.html?vid=n0163mjor1o&tiny=0&auto=0" allowfullscreen></iframe>

Just copy and paster the url in the src: http://v.qq.com/iframe/player.html?vid=n0163mjor1o

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/Elico-Corp/odoo-addons/issues>`_.
In case of trouble, please check there if your issue has already been reported.

Credits
=======

Contributors
------------

* Siyuan Gu <[email protected]>
* Ruter Lyu <[email protected]>

Maintainer
----------

.. image:: https://www.elico-corp.com/logo.png
:alt: Elico Corp
:target: https://www.elico-corp.com

This module is maintained by Elico Corporation.

Elico Corp is an innovative actor in China, Hong-Kong and Singapore servicing
well known international companies and as well as local mid-sized businesses.
Since 2010, our seasoned Sino-European consultants have been providing full
range Odoo services:

* Business consultancy for Gap analysis, BPM, operational work-flows review.
* Ready-to-use ERP packages aimed at starting businesses.
* Odoo implementation for manufacturing, international trading, service industry
and e-commerce.
* Connectors and integration with 3rd party software (Magento, Taobao, Coswin,
Joomla, Prestashop, Tradevine etc...).
* Odoo Support services such as developments, training, maintenance and hosting.

Our headquarters are located in Shanghai with branch in Singapore servicing
customers from all over Asia Pacific.

Contact information: `Sales <[email protected]>`__
1 change: 1 addition & 0 deletions website_slides_qq_video/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
15 changes: 15 additions & 0 deletions website_slides_qq_video/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# © 2015-2019 Elico corp (www.elico-corp.com)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
{
'name': 'Website Slides upload QQ video',
'version': '12.0.1.0.0',
'depends': [
'website_slides',
],
'author': 'Elico Corp',
'support': 'Elico Corp',
'license': 'LGPL-3',
'website': 'https://www.elico-corp.com',
'installable': True,
'application': False,
}
1 change: 1 addition & 0 deletions website_slides_qq_video/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import slides
111 changes: 111 additions & 0 deletions website_slides_qq_video/models/slides.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# © 2015-2019 Elico corp (www.elico-corp.com)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).

import re
import base64
import json
from urllib.parse import urlencode
from urllib.request import urlopen, Request
from urllib.error import HTTPError, URLError

from odoo import models


class Slide(models.Model):
_inherit = 'slide.slide'

def _get_embed_code(self):
super(Slide, self)._get_embed_code()

for record in self:
if record.slide_type == 'video':
if record.document_id and record.mime_type == "qq":
record.embed_code = """
<iframe frameborder="0" width="640" height="498"
src="http://v.qq.com/iframe/player.html?vid=%s&tiny=0&auto=0"
allowfullscreen></iframe>
""" % (record.document_id)

# for qq vedio
def _fetch_qq_video_data(self, base_url, data, content_type=False):
result = {'values': dict()}
try:
if content_type == 'json':
if data:
base_url = base_url + '%s&otype=json' % urlencode(data)
req = Request(base_url)
rsp_data = urlopen(req).read()
content = rsp_data.decode('utf-8').split('=')[1].rstrip(';')
result['values'] = json.loads(content)

if result['values'].get('msg'):
result['error'] = result['values'].get('msg')
elif content_type == 'image':
content = base64.b64encode(urlopen(base_url).read())
result['values'] = content
else:
result['values'] = ""
except HTTPError as e:
result['error'] = e.read()
e.close()
except URLError as e:
result['error'] = e.reason
return result

def _find_document_data_from_url(self, url):
# QQ video
expr = re.compile(r'.*(v.qq.com).*(vid=?)([^#\&\?]*).*')
arg = expr.match(url)
document_id = arg and arg.group(3) or False
if document_id:
return ('qq_video', document_id)

return super(Slide, self)._find_document_data_from_url()

def _parse_qq_video_title(self, res):
try:
title = res['values']['vl']['vi'][0]['ti']
except:
title = ""

return title

def _parse_qq_video_thumbnails(self, res, document_id):
try:
head = "http://vpic.video.qq.com/"
link = res['values']['vl']['vi'][0]['ul']['ui'][3]['url'].split(
"http://video.dispatch.tc.qq.com/")[1]
jpg = document_id + "_160_90_3.jpg"
img_url = head + link + jpg
except:
img_url = ""

return img_url

def _parse_qq_video_document(self, document_id, only_preview_fields):
fetch_res = self._fetch_qq_video_data(
'http://vv.video.qq.com/getinfo?', {'vid': document_id}, 'json'
)

if fetch_res.get('error'):
return fetch_res

title = self._parse_qq_video_title(fetch_res)
img_url = self._parse_qq_video_thumbnails(fetch_res, document_id)

values = {'slide_type': 'video', 'document_id': document_id}

if only_preview_fields:
values.update({
'url_src': img_url,
'title': title,
})

return values

values.update({
'name': title,
'image': self._fetch_qq_video_data(img_url, {}, 'image')['values'],
'mime_type': "qq"
})
return {'values': values}