This commit is contained in:
339
MyPlayer/LICENSE
Normal file
339
MyPlayer/LICENSE
Normal file
@@ -0,0 +1,339 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc., <http://fsf.org/>
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
{description}
|
||||
Copyright (C) {year} {fullname}
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
{signature of Ty Coon}, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
||||
93
MyPlayer/Plugin.php
Normal file
93
MyPlayer/Plugin.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
/**
|
||||
* 我的播放器
|
||||
*
|
||||
* @package MyPlayer
|
||||
* @author perichr
|
||||
* @version 1.1.3
|
||||
* @link http://perichr.org
|
||||
*/
|
||||
class MyPlayer_Plugin implements Typecho_Plugin_Interface
|
||||
{
|
||||
/**
|
||||
* 激活插件方法,如果激活失败,直接抛出异常
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws Typecho_Plugin_Exception
|
||||
*/
|
||||
public static function activate()
|
||||
{
|
||||
Typecho_Plugin::factory('Widget_Archive')->footer = array('MyPlayer_Plugin', 'Converter');
|
||||
Typecho_Plugin::factory('admin/write-post.php')->bottom = array('MyPlayer_Plugin', 'EditorTool');
|
||||
Typecho_Plugin::factory('admin/write-page.php')->bottom = array('MyPlayer_Plugin', 'EditorTool'); }
|
||||
|
||||
/**
|
||||
* 获取插件配置面板
|
||||
*
|
||||
* @access public
|
||||
* @param Typecho_Widget_Helper_Form $form 配置面板
|
||||
* @return void
|
||||
*/
|
||||
public static function config(Typecho_Widget_Helper_Form $form)
|
||||
{
|
||||
$query_parent = new Typecho_Widget_Helper_Form_Element_Text('query_parent', NULL, '', _t('应用插件的范围'), _t('请使用css选择器来指定插件应用的范围。如果是默认主题,可以使用“.post”;如果是P酱的主题,可以使用“.entry-content”;实在弄不清就留空。'));
|
||||
$query_parent->input->setAttribute('class', 'mini');
|
||||
$form->addInput($query_parent);
|
||||
|
||||
$mode= new Typecho_Widget_Helper_Form_Element_Radio('mode',
|
||||
array( 'all' => _t('转换所有可用播放器'),
|
||||
'click' => _t('等待点击'),
|
||||
'first' => _t('转换首个可用播放器,其它等待点击')
|
||||
),
|
||||
'first', _t('是否自动转换链接'));
|
||||
$form->addInput($mode);
|
||||
|
||||
$audio_player_theme = new Typecho_Widget_Helper_Form_Element_Text('audio_player_theme', NULL, '#FFFFFF|#FF9933|#FF6633', _t('音频播放器的配色'), _t(''));
|
||||
$form->addInput($audio_player_theme);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 个人用户的配置面板
|
||||
*
|
||||
* @access public
|
||||
* @param Typecho_Widget_Helper_Form $form
|
||||
* @return void
|
||||
*/
|
||||
public static function personalConfig(Typecho_Widget_Helper_Form $form){}
|
||||
|
||||
/**
|
||||
* 禁用插件方法,如果禁用失败,直接抛出异常
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws Typecho_Plugin_Exception
|
||||
*/
|
||||
public static function deactivate(){}
|
||||
|
||||
/**
|
||||
* 插件的实现方法
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public static function Converter()
|
||||
{
|
||||
$options = Helper::options();
|
||||
$config = $options->plugin('MyPlayer');
|
||||
$o = array( );
|
||||
$o[ 'query_parent' ] = $config->query_parent;
|
||||
$o[ 'mode' ] = $config->mode;
|
||||
$o[ 'theme' ] = $config->audio_player_theme;
|
||||
echo '<script src="' . Typecho_Common::url('MyPlayer/assets/js/perichr.js', $options->pluginUrl) . '" data-PK="MyPlayer" data-options="' . htmlentities( json_encode( $o ), ENT_QUOTES ) . '" data-init="convert.js"></script>';
|
||||
}
|
||||
public static function EditorTool()
|
||||
{
|
||||
$options = Helper::options();
|
||||
$config = $options->plugin('MyPlayer');
|
||||
echo '<script src="' . Typecho_Common::url('MyPlayer/assets/js/perichr.js', $options->pluginUrl) . '" data-PK="MyPlayer" data-init="editor.js"></script>';
|
||||
}
|
||||
}
|
||||
|
||||
81
MyPlayer/README.md
Normal file
81
MyPlayer/README.md
Normal file
@@ -0,0 +1,81 @@
|
||||
MyPlayer
|
||||
========
|
||||
|
||||
Typecho外链播放器转换插件
|
||||
|
||||
> :no_entry:jPlayer调用失效,仅优酷/音悦台/哔哩哔哩链接替换可用。
|
||||
|
||||
## 简介
|
||||
|
||||
这是一个[Typecho][1]插件,将指向音乐或者视频页面的链接转换为相应外站播放器的插件。
|
||||
|
||||
目前支持虾米、优酷、土豆、爱奇艺、音悦台、乐视、56、哔哩哔哩、新浪的播放页面链接。
|
||||
|
||||
特别提供了一个简单的小型音频播放器,以供MP3文件链接和虾米音乐链接使用。
|
||||
|
||||
另简单支持flash和html5音频。
|
||||
|
||||
## 特征
|
||||
|
||||
### 无侵入性
|
||||
|
||||
本插件具有“无侵入性”。由于文档中只是使用普通链接,在关闭、移除了插件后,文档内容不受影响,没有数据丢失或冗余,仅仅由点击链接展开播放器降级为打开播放页面,是一种可接受的降级方式。使用后不喜欢本插件的可以随意关闭并删除之。
|
||||
|
||||
### 高扩展性
|
||||
|
||||
本插件使用比较简单的接口,扩展性强,可以轻松添加其他的外链播放器。
|
||||
|
||||
## 需求
|
||||
|
||||
最低Typecho0.9版本。
|
||||
注:未在Typecho0.8版本中测试。
|
||||
|
||||
## 安装
|
||||
|
||||
### 推荐
|
||||
|
||||
首先安装[Typecho 应用商店 插件][4]。在该插件中可以找到本插件的稳定发布版,后台下载安装。
|
||||
|
||||
### 手动
|
||||
|
||||
在Typecho的usr/plugins/目录下建立MyPlayer文件夹,将本插件的文件置入该文件夹,并进入后台插件管理界面中激活。
|
||||
|
||||
## 用法
|
||||
|
||||
在文章中只需要使用指向音乐或者视频播放页面的普通链接即可。例如:
|
||||
|
||||
```markdown
|
||||
[断点](http://www.xiami.com/song/72299)
|
||||
|
||||
[欧派之歌·抖抖抖腿根本停不下来](http://www.bilibili.com/video/av1192762/)
|
||||
```
|
||||
|
||||
以上为Markdown代码,html代码同理,自行脑补即可。
|
||||
|
||||
插件单独提供了一个html插入按钮,用于应对一些复杂情况(通常只在直接插入音视频文件链接时才有可能需要)。
|
||||
|
||||
顺便一说,Markdown是直接支持html的。
|
||||
|
||||
|
||||
## 实现
|
||||
|
||||
插件通过js脚本检查指定范围内的链接,当匹配某个插件可识别的页面时,在前台转换为对应的官方外站播放器。
|
||||
|
||||
具体的方法主要是通过地址中的特征字符串匹配,自行拼接出外链播放器地址。
|
||||
|
||||
对于特定的网站,可能无法通过简单的页面链接获取足够信息时,则需要通过后台抓取页面内容以获得相关数据。
|
||||
|
||||
## 其它
|
||||
|
||||
稳定版发布地址:[typecho-fan插件集][3]
|
||||
|
||||
开发版发布地址:[MyPlayer On Github][2]
|
||||
|
||||
历史版本:[MyPlayer Releases][5]
|
||||
|
||||
[1]:http://typecho.org
|
||||
[2]:https://github.com/perichr/Typecho_Plugin_MyPlayer
|
||||
[3]:https://github.com/typecho-fans/plugins/tree/master/MyPlayer
|
||||
[4]:https://github.com/typecho-app-store/AppStore
|
||||
[5]:https://github.com/perichr/Typecho_Plugin_MyPlayer/releases
|
||||
|
||||
60
MyPlayer/api.php
Normal file
60
MyPlayer/api.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
function MakeDir( $path ) {
|
||||
return is_writeable( $path ) || mkdir( $path, 0777, true );
|
||||
}
|
||||
function TryGetParam( $key, &$value ){
|
||||
if( isset( $_GET[$key] ) && $_GET[$key] ){
|
||||
$value = $_GET[$key];
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function GetUrlContent( $url ){
|
||||
$curl = curl_init( $url );
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($curl, CURLOPT_FOLLOWLOCATION,1);
|
||||
curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16');
|
||||
$res=curl_exec($curl);
|
||||
curl_close($curl);
|
||||
return $res;
|
||||
}
|
||||
abstract class API {
|
||||
protected $service;
|
||||
protected $key;
|
||||
protected $data;
|
||||
protected $cachetime;
|
||||
public function __construct( ){
|
||||
$this->cachetime = 86400;
|
||||
$this->service = strtolower( get_class( $this ) );
|
||||
$this->data = null;
|
||||
$this->LoadData( );
|
||||
}
|
||||
protected function LoadData( ) {
|
||||
$this->LoadRemote( );
|
||||
}
|
||||
public function GetData( $callback = null ) {
|
||||
$data = json_encode( $this->data );
|
||||
if( is_null( $callback ) ) {
|
||||
return $data;
|
||||
} else {
|
||||
return "{$callback}({$data})";
|
||||
}
|
||||
}
|
||||
protected abstract function LoadRemote( );
|
||||
}
|
||||
if( TryGetParam( 'service', $service ) ) {
|
||||
$service = strtolower( $service );
|
||||
$apifile = "api/{$service}.php";
|
||||
if( file_exists( $apifile ) ){
|
||||
include( $apifile );
|
||||
$api = new $service( );
|
||||
if( TryGetParam( 'callback', $callback ) ) {
|
||||
header( 'Content-type:text/javascript' );
|
||||
echo $api->GetData( $callback );
|
||||
} else {
|
||||
header( 'Content-type:application/json' );
|
||||
echo $api->GetData( );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
17
MyPlayer/api/iqiyi.php
Normal file
17
MyPlayer/api/iqiyi.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/*
|
||||
* 爱奇艺
|
||||
*/
|
||||
class iqiyi extends API{
|
||||
protected function LoadRemote( ) {
|
||||
if( TryGetParam( 'id', $id ) ) {
|
||||
$html = GetUrlContent( "http://www.iqiyi.com/v_{$id}.html" );
|
||||
$count = preg_match_all( '/\"vid\":\"([0-9a-z]+)\"/s', $html, $matchs );
|
||||
if( $count ){
|
||||
$vid = $matchs[1][0];
|
||||
$this->data = array( );
|
||||
$this->data['url'] = "http://player.video.qiyi.com/{$vid}/0/0/v_{$id}.swf";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
31
MyPlayer/api/lyric.php
Normal file
31
MyPlayer/api/lyric.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/*
|
||||
* 歌词文件
|
||||
*/
|
||||
class lyric extends API{
|
||||
protected function LoadRemote( ) {
|
||||
if( TryGetParam( 'url', $url ) ) {
|
||||
$source = GetUrlContent( $url );
|
||||
$this->data['source'] = $source;
|
||||
//$this->data['json'] = $this->GetJson($source);
|
||||
}
|
||||
}
|
||||
function GetJson($lyric){
|
||||
$lrc = array();
|
||||
$preg = '/^(.*?)$/m';
|
||||
$count = preg_match_all( $preg, $lyric, $match );
|
||||
foreach( $match[1] as $line ) {
|
||||
$preg = '/\[(\d{2}:.*?)\]/s';
|
||||
preg_match_all( $preg, $line, $m );
|
||||
$text = implode( '', $m[0] );
|
||||
$text = str_replace( $text, '' ,$line );
|
||||
foreach( $m[1] as $t ) {
|
||||
$i = explode( ':', $t );
|
||||
$time = $i[0] * 60 + $i[1];
|
||||
$lrc[] = array( $time, $text );
|
||||
}
|
||||
}
|
||||
sort( $lrc );
|
||||
return $lrc;
|
||||
}
|
||||
}
|
||||
18
MyPlayer/api/sina.php
Normal file
18
MyPlayer/api/sina.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
/*
|
||||
* 新浪视频
|
||||
*/
|
||||
class sina extends API{
|
||||
protected function LoadRemote( ) {
|
||||
if( TryGetParam( 'url', $url ) ) {
|
||||
$url = $url;
|
||||
$html = GetUrlContent( "http://dp.sina.cn/dpool/video/pad/play.php?url={$url}" );
|
||||
$count = preg_match_all( '/$SCOPE\[\'vid\'\]\s=\s"(\d+)";/s', $html, $matchs );
|
||||
if( $count ){
|
||||
$this->data = array( );
|
||||
$this->data['url'] = $matchs[1][0];
|
||||
$this->data['url'] = 'http://you.video.sina.com.cn/api/sinawebApi/outplayrefer.php/vid={$matchs[1][0]}/s.swf'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
212
MyPlayer/assets/js/api.js
Normal file
212
MyPlayer/assets/js/api.js
Normal file
@@ -0,0 +1,212 @@
|
||||
'use strict';
|
||||
P({
|
||||
id: 'api.js',
|
||||
key: 'MyPlayer',
|
||||
Init: function(me){
|
||||
var o = me.option, f = me.fn, Add = function(key, item) {
|
||||
o.apis[key] = item
|
||||
}, AddRange = function(list) {
|
||||
me.fn.each(list, Add)
|
||||
}
|
||||
o('apis', {})
|
||||
o('auto_sign', 'data-auto-play')
|
||||
AddRange({
|
||||
'虾米音乐': {
|
||||
'check': function(href) {
|
||||
return href && 0 == href.indexOf('http://www.xiami.com/song/')
|
||||
},
|
||||
'create': function(href) {
|
||||
this.base = 'flash'
|
||||
this.attributes.width = 257
|
||||
this.attributes.height = 33
|
||||
this.attributes.src = href.replace(/.*\/(\d+)\/?/, 'http://www.xiami.com/widget/1426712_$1/singlePlayer.swf')
|
||||
this.callback()
|
||||
}
|
||||
},
|
||||
'优酷视频': {
|
||||
'check': function(href) {
|
||||
return href && 0 == href.indexOf('http://v.youku.com/v_show/id_')
|
||||
},
|
||||
'create': function(href) {
|
||||
this.base = 'flash'
|
||||
this.attributes.width = 480
|
||||
this.attributes.height = 400
|
||||
this.attributes.src = href.replace(/^.*id_(.*)\.html$/g, 'http://player.youku.com/player.php/sid/$1/v.swf')
|
||||
this.callback()
|
||||
}
|
||||
},
|
||||
'土豆视频': {
|
||||
'check': function(href) {
|
||||
return href && 0 == href.indexOf('http://www.tudou.com/programs/view/')
|
||||
},
|
||||
'create': function(href) {
|
||||
this.base = 'flash'
|
||||
this.attributes.width = 480
|
||||
this.attributes.height = 400
|
||||
this.attributes.src = href.replace('programs\/view', 'v') + 'v.swf'
|
||||
this.callback()
|
||||
}
|
||||
},
|
||||
'爱奇艺视频': {
|
||||
'check': function(href) {
|
||||
return href && 0 == href.indexOf('http://www.iqiyi.com/v_')
|
||||
},
|
||||
'create': function(href) {
|
||||
this.base = 'flash'
|
||||
this.attributes.width = 480
|
||||
this.attributes.height = 400
|
||||
var id = href.replace(/^.*v_(.*)\.html$/g, '$1'),bind = this
|
||||
f.jsonp({
|
||||
url: me.GetPath('../../api.php'),
|
||||
data: {service: 'iqiyi', id: id},
|
||||
success: function(data) {
|
||||
if (data.url) {
|
||||
bind.attributes.src = data.url
|
||||
bind.callback()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
'音悦台MV': {
|
||||
'check': function(href) {
|
||||
return href && 0 == href.indexOf('http://v.yinyuetai.com/video/')
|
||||
},
|
||||
'create': function(href) {
|
||||
this.base = 'flash'
|
||||
this.attributes.width = 480
|
||||
this.attributes.height = 334
|
||||
this.attributes.src = href.replace(/^.*\/(\d*)$/g, 'http://player.yinyuetai.com/video/player/$1/v_0.swf')
|
||||
this.callback()
|
||||
}
|
||||
},
|
||||
'乐视TV': {
|
||||
'check': function(href) {
|
||||
return href && 0 == href.indexOf('http://www.letv.com/ptv/vplay/')
|
||||
},
|
||||
'create': function(href) {
|
||||
this.base = 'flash'
|
||||
this.attributes.width = 541
|
||||
this.attributes.height = 450
|
||||
this.attributes.src = href.replace(/^.*\/(\d*)\.html$/g, 'http://i7.imgs.letv.com/player/swfPlayer.swf?autoPlay=0&id=$1')
|
||||
this.callback()
|
||||
}
|
||||
},
|
||||
'56视频': {
|
||||
'check': function(href) {
|
||||
return href && /http:\/\/www.56.com\/[u\d]+\/v_/.test(href)
|
||||
},
|
||||
'create': function(href) {
|
||||
this.base = 'flash'
|
||||
this.attributes.width = 480
|
||||
this.attributes.height = 408
|
||||
this.attributes.src = href.replace(/^.*\/v_(.*)\.html$/g, 'http://player.56.com/v_$id.swf')
|
||||
this.callback()
|
||||
}
|
||||
},
|
||||
'哔哩哔哩': {
|
||||
'check': function(href) {
|
||||
return /http:\/\/(www\.bilibili\.com|www\.bilibili\.tv|bilibili\.kankanews\.com)?\/video\/av([0-9]+)\/(?:index_([0-9]+)\.html)?/.test(href)
|
||||
},
|
||||
'create': function(href) {
|
||||
this.base = 'flash'
|
||||
this.attributes.width = 544
|
||||
this.attributes.height = 452
|
||||
if (href.indexOf('.html') == -1) href += "/index_1.html"
|
||||
var aid = href.replace(/^.*\/av(\d+)\/.*/g, '$1'),
|
||||
page = href.replace(/^.*\/index_(\d+)\.html$/g, '$1'),
|
||||
bind = this
|
||||
this.attributes.src = 'http://static.hdslb.com//miniloader.swf?aid=' + aid + '&page=' + page
|
||||
this.callback()
|
||||
}
|
||||
},
|
||||
'新浪视频': {
|
||||
'check': function(href) {
|
||||
return href && (/#\d+$/.test(href) || /^http:\/\/video\.sina\.com\.cn\/.+\d+\.html$/.test(href))
|
||||
},
|
||||
'create': function(href) {
|
||||
var bind = this, bindWithVid = function( vid ){
|
||||
bind.base = 'flash'
|
||||
bind.attributes.width = 480
|
||||
bind.attributes.height = 370
|
||||
bind.attributes.src = 'http://you.video.sina.com.cn/api/sinawebApi/outplayrefer.php/vid=' + vid + '/s.swf'
|
||||
bind.callback()
|
||||
}
|
||||
if(/#\d+$/.test(href)){
|
||||
bindWithVid( href.replace(/.+#(\d+)$/g, '$1') )
|
||||
return
|
||||
}
|
||||
f.jsonp({
|
||||
url: me.GetPath('../../api.php'),
|
||||
data: {service: 'sina', id: encodeURIComeonent(href)},
|
||||
success: function(data) {
|
||||
if (data.url) {
|
||||
bindWithVid( data.url )
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
'mp3': {
|
||||
'optional': 'type, lyrics',
|
||||
'check': function(href, type) {
|
||||
return type ? /^mp3$/.test(type) : (href && /\.(ogg|mp3)$/.test(href))
|
||||
},
|
||||
'create': function(href) {
|
||||
this.base = 'iframe'
|
||||
var op = {media: [], theme: f.trim(o('theme'))}
|
||||
op.media.push({
|
||||
url: href,
|
||||
title: this.element.innerHTML,
|
||||
lyrics: this.lyrics
|
||||
})
|
||||
if(this.element.getAttribute(o.auto_sign)){
|
||||
op.autoplay = true
|
||||
}
|
||||
this.attributes.src = me.GetPath('../../player/#') + JSON.stringify(op)
|
||||
this.attributes.width = 223
|
||||
this.attributes.height = 24
|
||||
this.callback()
|
||||
}
|
||||
},
|
||||
'html5 audio': {
|
||||
'optional': 'type, lyrics',
|
||||
'check': function(href, type) {
|
||||
return type ? /^ogg|mp3$/.test(type) : (href && /\.(ogg|mp3)$/.test(href))
|
||||
},
|
||||
'create': function(href) {
|
||||
this.base = 'audio'
|
||||
this.attributes.src = href
|
||||
this.callback()
|
||||
}
|
||||
},
|
||||
'html5 video': {
|
||||
'optional': 'type, width, height',
|
||||
'check': function(href, type) {
|
||||
return type ? /^ogg|mp4$/.test(type) : (href && /\.(ogv|mp4)$/.test(href))
|
||||
},
|
||||
'create': function(href) {
|
||||
this.base = 'video'
|
||||
this.attributs.width = this.width || 480
|
||||
this.attributs.height = this.height || 400
|
||||
this.attributes.src = href
|
||||
this.callback()
|
||||
}
|
||||
},
|
||||
'flash': {
|
||||
'optional': 'type, width, height',
|
||||
'check': function(href, type) {
|
||||
return type ? /^swf$/.test(type) : (href && /\.swf$/.test(href))
|
||||
},
|
||||
'create': function(href) {
|
||||
this.base = 'flash'
|
||||
this.attributs.width = this.width || 480
|
||||
this.attributs.height = this.height || 400
|
||||
this.attributs.src = href
|
||||
this.callback()
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
}
|
||||
})
|
||||
127
MyPlayer/assets/js/convert.js
Normal file
127
MyPlayer/assets/js/convert.js
Normal file
@@ -0,0 +1,127 @@
|
||||
'use strict';
|
||||
P({
|
||||
id: 'convert.js',
|
||||
key: 'MyPlayer',
|
||||
Init: function(me){
|
||||
me.Load('api.js', function(){
|
||||
var f = me.fn,
|
||||
o = me.option,
|
||||
api = me.GetPlugin('api.js')
|
||||
o('data_sign', 'data-me-sign')
|
||||
if (!o('query_parent')) {
|
||||
o.query_parent = f.qs('.post') ? '.post' : f.qs('.entry-content') ? '.entry-content' : ''
|
||||
}
|
||||
var mode = o('mode')
|
||||
o.mode = {
|
||||
ALL: mode == 'all',
|
||||
CLICK: mode == 'click',
|
||||
FIRST: mode == 'first',
|
||||
}
|
||||
var _b = {
|
||||
'flash': {
|
||||
'attributes': {
|
||||
'mimetype': 'application/x-shockwave-flash',
|
||||
'pluginspage': 'http://www.adobe.com/go/getflashplayer',
|
||||
'wmode': 'transparent',
|
||||
'quality': 'high',
|
||||
'allowFullScreen': true,
|
||||
'allowScriptAccess': 'always',
|
||||
'width': 480,
|
||||
'height': 400
|
||||
},
|
||||
'tag': 'embed'
|
||||
},
|
||||
'iframe': {
|
||||
'attributes': {
|
||||
'frameborder': '0',
|
||||
'framespacing': '0',
|
||||
'width': 480,
|
||||
'height': 400
|
||||
},
|
||||
'tag': 'iframe'
|
||||
},
|
||||
'audio': {
|
||||
'attributes': {
|
||||
'controls': 'controls',
|
||||
'autoplay': 'autoplay',
|
||||
'loop': 'loop',
|
||||
'width': 300,
|
||||
'height': 30
|
||||
},
|
||||
'tag': 'audio'
|
||||
},
|
||||
'video': {
|
||||
'attributes': {
|
||||
'controls': 'controls',
|
||||
'autoplay': 'autoplay',
|
||||
'width': 480,
|
||||
'height': 400
|
||||
},
|
||||
'tag': 'video'
|
||||
}
|
||||
}
|
||||
var Ck = me.CheckMode = function(el) {
|
||||
var data_sign = o('data_sign'),
|
||||
mode = el.getAttribute(data_sign)
|
||||
if (mode == 'false') return false
|
||||
if (mode) return mode
|
||||
f.each(api.option.apis, function(key, item) {
|
||||
if (item.check.call(el, el.href, el.getAttribute('data-type'))) {
|
||||
mode = key
|
||||
return false
|
||||
}
|
||||
})
|
||||
el.setAttribute(data_sign, mode || 'false')
|
||||
return mode
|
||||
},
|
||||
Co = me.Convert2Player = function(el) {
|
||||
var mode = Ck(el)
|
||||
if (mode) {
|
||||
var bind = {
|
||||
element: el,
|
||||
callback: callback,
|
||||
attributes: {},
|
||||
width: el.getAttribute('data-width'),
|
||||
height: el.getAttribute('data-height'),
|
||||
lyrics: el.getAttribute('data-lyrics'),
|
||||
type: el.getAttribute('data-type'),
|
||||
options: el.getAttribute('data-options'),
|
||||
}
|
||||
api.option.apis[mode].create.call(bind, el.href)
|
||||
return true
|
||||
}
|
||||
|
||||
function callback() {
|
||||
var attributes = this.attributes,
|
||||
base = _b[this.base] || {}
|
||||
f.extend(attributes, base.attributes, false)
|
||||
var swf = f.element(base.tag, attributes)
|
||||
f.after(el, swf)
|
||||
f.remove(el)
|
||||
}
|
||||
}
|
||||
|
||||
// 初始化完毕
|
||||
|
||||
|
||||
var link_list = f.qa(o.query_parent + ' a'),
|
||||
conv = o.mode.ALL || o.mode.FIRST,
|
||||
click = function(event) {
|
||||
var target = event.target,
|
||||
converted = Co(target)
|
||||
f.off(target, 'click', click)
|
||||
if (converted) event.preventDefault()
|
||||
}
|
||||
f.each(link_list, function() {
|
||||
var link = this
|
||||
if (conv) {
|
||||
var conved = Co(link)
|
||||
if (o.mode.FIRST && conved) conv = false
|
||||
} else {
|
||||
link.setAttribute(api.option.auto_sign, 'true')
|
||||
f.on(link, 'click', click)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
119
MyPlayer/assets/js/editor.js
Normal file
119
MyPlayer/assets/js/editor.js
Normal file
@@ -0,0 +1,119 @@
|
||||
'use strict';
|
||||
P({
|
||||
id: 'editor.js',
|
||||
key: 'MyPlayer',
|
||||
Init: function(me) {
|
||||
me.Load('api.js', function(){
|
||||
var f = me.fn,
|
||||
o = me.option,
|
||||
api = me.GetPlugin('api.js'),
|
||||
apis = api.option.apis
|
||||
$(function() {
|
||||
var $wbr,
|
||||
textarea = f.id('text'),
|
||||
$textarea = $(textarea),
|
||||
md = $('input[name=markdown]').size() == 1 ,
|
||||
$button = $('<li class="wmd-button" id="wmd-myplayer-button" title="MyPlayer" ><span style="background: none; line-height: 20px;">MP</span></li>').on('click', function(event) {
|
||||
show_dialog( )
|
||||
}),
|
||||
$title = $('<input type="text" placeholder="标题" />'),
|
||||
$url = $('<input type="text" placeholder="网址" />'),
|
||||
$optional = {
|
||||
type:$('<input type="text" placeholder="格式 | 强制指定格式" />'),
|
||||
lyrics:$('<input type="text" placeholder="歌词 | 仅对音乐文件有效" />'),
|
||||
width:$('<input type="text" style="width:50%" placeholder="宽度 | 指定影像宽度" />'),
|
||||
height:$('<input type="text" style="width:50%" placeholder="高度 | 指定影像高度" />')
|
||||
},
|
||||
$ok = $('<button type="button" class="btn btn-s primary">确定</button>'),
|
||||
$cancel = $('<button type="button" class="btn btn-s">取消</button>'),
|
||||
$tip = $('<span></span>'),
|
||||
$form = $('<form>').append($title, $url, $optional.type, $optional.lyrics, $optional.width, $optional.height, $ok, $cancel, $tip),
|
||||
$dialog = $('<div class="wmd-prompt-dialog" rol="dialog" style="margin-top: -200px;">').append('<div><p><b>插入链接</b></p><p>请在下方的输入框内输入要插入的媒体页面链接。</p></div>').append($form),
|
||||
$pop = $('<div class="wmd-prompt-background" style="position: absolute; top: 0px; z-index: 1000; opacity: 0.5; height: 905px; left: 0px; width: 100%;">').add($dialog)
|
||||
var text = []
|
||||
$.each(apis,function(index){
|
||||
text.push(index)
|
||||
})
|
||||
$('div',$dialog).append($('<p>').text('目前支持的有' + text.join('、') + '等。'))
|
||||
if (md){
|
||||
insert_button()
|
||||
}else{
|
||||
$('.notice button.yes').click(function(){
|
||||
md = true
|
||||
insert_button()
|
||||
})
|
||||
$('.notice button.no').click(function(){
|
||||
md = false
|
||||
insert_button()
|
||||
})
|
||||
}
|
||||
function insert_button(){
|
||||
if (md) {
|
||||
$wbr = $('#wmd-button-row').append($('<li class="wmd-spacer wmd-spacer1" id="wmd-spacer1"></li>'))
|
||||
} else {
|
||||
$wbr = $('<ul class="wmd-button-row">').insertAfter('.url-slug')
|
||||
}
|
||||
$wbr.append($('<li class="wmd-button" id="wmd-myplayer-button" title="MyPlayer" ></li>').append($button))
|
||||
}
|
||||
|
||||
function show_dialog() {
|
||||
$('input', $pop).val('').attr('readonly',false).show()
|
||||
$tip.text('请输入有效的链接!')
|
||||
check($url.val())
|
||||
$url.val('http://')
|
||||
$cancel.click(function(){
|
||||
$pop.remove()
|
||||
}),
|
||||
$ok.click(function(){
|
||||
write()
|
||||
$cancel.click()
|
||||
})
|
||||
$url.keyup(onkeyup)
|
||||
$optional.type.keyup(onkeyup)
|
||||
$title.val($textarea.getSelection().text)
|
||||
$pop.appendTo(document.body)
|
||||
}
|
||||
var mode = {}, time
|
||||
function onkeyup(){
|
||||
clearTimeout(time)
|
||||
time = setTimeout(function(){
|
||||
mode.key = check($url.val(), $optional.type.val())
|
||||
$tip.text(mode.key ? '将启用 ' + mode.key + ' 播放器!' : '这是不认识的链接!')
|
||||
f.each($optional, function(key, $input){
|
||||
if( !mode.key || (apis[mode.key].optional && apis[mode.key].optional.indexOf(key)>-1) ) {
|
||||
$input.attr('readonly',false).show()
|
||||
mode[key] = true
|
||||
} else{
|
||||
$input.attr('readonly',true).hide()
|
||||
mode[key] = false
|
||||
}
|
||||
})
|
||||
}, 100);
|
||||
}
|
||||
function check(href, type) {
|
||||
var result = false
|
||||
f.each(apis, function(key, api) {
|
||||
if (api.check.call(null, href, type)) {
|
||||
result = key
|
||||
return false
|
||||
}
|
||||
})
|
||||
return result
|
||||
}
|
||||
function write() {
|
||||
var sel = $textarea.getSelection(), end,
|
||||
html = '<a href="' + $url.val() + '"'
|
||||
if(mode && mode['type'] && $optional.type.val()) html += ' data-type="' + $optional.type.val() + '"'
|
||||
if(mode && mode['lyrics'] && $optional.lyrics.val()) html += ' data-lyrics="' + $optional.lyrics.val() + '"'
|
||||
if(mode && mode['width'] && $optional.width.val()) html += ' data-width="' + $optional.width.val() + '"'
|
||||
if(mode && mode['height'] && $optional.height.val()) html += ' data-height="' + $optional.height.val() + '"'
|
||||
html += '>' + $title.val() + '</a>'
|
||||
end = (sel ? sel.start : 0) + html.length
|
||||
$textarea.replaceSelection(html)
|
||||
$textarea.setSelection(end, end)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
1
MyPlayer/assets/js/perichr.js
Normal file
1
MyPlayer/assets/js/perichr.js
Normal file
File diff suppressed because one or more lines are too long
211
MyPlayer/assets/js/player.js
Normal file
211
MyPlayer/assets/js/player.js
Normal file
@@ -0,0 +1,211 @@
|
||||
'use strict';
|
||||
//MyPlayer 播放页面
|
||||
(function(root, doc, $, undefined){
|
||||
var defaultOptions = {media:[],front:'white',background:'orange',actived:'red'},
|
||||
$jplayer, $player, $list, $state, $title, $progress, $lyric, options = {}, current = -1, length, first = true
|
||||
$(function(){
|
||||
getOptions()
|
||||
length = options.media.length
|
||||
init()
|
||||
setTheme(options)
|
||||
if(options.media && length > 0 ){
|
||||
if(length>1){
|
||||
$('body').append($list)
|
||||
}
|
||||
next()
|
||||
}
|
||||
})
|
||||
function next(){
|
||||
if(current == length -1 ){
|
||||
current = -1
|
||||
}
|
||||
load(options.media[++current])
|
||||
}
|
||||
function setTheme(){
|
||||
if(options.front){
|
||||
$player.css('color',options.front)
|
||||
$state.css({
|
||||
'border-left-color':options.front,
|
||||
'border-right-color':options.front
|
||||
})
|
||||
}
|
||||
if(options.background){
|
||||
$player.css('background-color',options.background)
|
||||
}
|
||||
if(options.actived){
|
||||
$progress.css('background-color',options.actived)
|
||||
}
|
||||
}
|
||||
function loading(text){
|
||||
$title.text(text)
|
||||
$player.attr('title',text)
|
||||
doc.title = text
|
||||
}
|
||||
function load(media){
|
||||
if($jplayer){
|
||||
$jplayer.jPlayer('destroy')
|
||||
$jplayer.unbind().empty().remove()
|
||||
$jplayer = null
|
||||
}
|
||||
if(media.url){
|
||||
setNewMedia(media)
|
||||
}else if(media.xiami){
|
||||
loading('正在尝试载入虾米音乐……')
|
||||
$.ajax({
|
||||
url: '../api.php',
|
||||
data:{service: 'xiami',id: media.xiami},
|
||||
type: 'GET',
|
||||
dataType: 'jsonp',
|
||||
async: false,
|
||||
success: function(data) {
|
||||
if(data[0]){
|
||||
data = data[0]
|
||||
media.url = data.url
|
||||
media.title = data.title
|
||||
media.artist = data.artist
|
||||
media.lyric = data.lyric_url
|
||||
setNewMedia(media)
|
||||
}
|
||||
},
|
||||
error:function(){
|
||||
options.media.splice(current,1)
|
||||
length--
|
||||
current--
|
||||
next()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
function getType(url){
|
||||
var index = url.indexOf('?')
|
||||
if(index>0){
|
||||
url = url.substring(0,index)
|
||||
}
|
||||
index = url.lastIndexOf('.')
|
||||
return url.substring(index+1)
|
||||
}
|
||||
function parseLyric(text){
|
||||
text = text.split('\r\n')
|
||||
var lyric = []
|
||||
$.each(text, function(index, value){
|
||||
value = $.trim(value)
|
||||
var d = value.match(/^\[\d{2}:\d{2}((\.|\:)\d{2})\]/g)
|
||||
if(!d) return
|
||||
var dt = String(d).split(':')
|
||||
var t = value.split(d)
|
||||
var _t = Math.round(parseInt(dt[0].split('[')[1])*60+parseFloat(dt[1].split(']')[0])*100)/100
|
||||
lyric.push([_t, t[1]])
|
||||
})
|
||||
return lyric
|
||||
}
|
||||
function setNewMedia(media){
|
||||
media.type = media.type || getType( media.url ) || 'mp3'
|
||||
$jplayer = $('<div>').appendTo($player).attr('id','jplayer')
|
||||
.bind($.jPlayer.event.timeupdate, function(e) {
|
||||
$progress.width(Math.round(e.jPlayer.status.currentPercentAbsolute / 100 * $player.width()))
|
||||
})
|
||||
.jPlayer({
|
||||
ready:function(){
|
||||
$title.text(media.title + (media.artist? ' by ' + media.artist : ''))
|
||||
$player.attr('title',media.title)
|
||||
doc.title = media.title
|
||||
var obj ={}
|
||||
obj[media.type] = media.url
|
||||
$jplayer.jPlayer('setMedia', obj)
|
||||
if(!first || options.autoplay){
|
||||
play()
|
||||
first = false
|
||||
}
|
||||
},
|
||||
ended:function(){
|
||||
$progress.width('0')
|
||||
if(length == 1){
|
||||
play()
|
||||
}else{
|
||||
next()
|
||||
}
|
||||
},
|
||||
consoleAlerts:true,
|
||||
preload: 'none',
|
||||
swfPath: '../assets/swf/'
|
||||
,supplied: media.type
|
||||
})
|
||||
if(media.lyric){
|
||||
$.ajax({
|
||||
url: '../api.php',
|
||||
data:{service: 'lyric', url: media.lyric},
|
||||
type: 'GET',
|
||||
async: false,
|
||||
success: function(data) {
|
||||
if(data && data.source){
|
||||
data = parseLyric(data.source)
|
||||
$jplayer.jPlayer.hasLyric = true
|
||||
var m = 0
|
||||
$jplayer.bind($.jPlayer.event.timeupdate, function(e) {
|
||||
if(e.jPlayer.status.currentTime < 0.5){
|
||||
m = 0
|
||||
}
|
||||
if ( m < data.length && e.jPlayer.status.currentTime > data[m][0]){
|
||||
$lyric.text(data[m][1])
|
||||
$player.attr('title',$lyric.text())
|
||||
m++
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
function getOptions(){
|
||||
options = $.extend(options, defaultOptions)
|
||||
try{
|
||||
$.extend(options, JSON.parse(document.location.hash.replace(/^#/,'')))
|
||||
}catch(e){
|
||||
}
|
||||
options.theme=options.theme.split('|')
|
||||
if(options.theme[0]){
|
||||
options.front = options.theme[0]
|
||||
}
|
||||
if(options.theme[1]){
|
||||
options.background = options.theme[1]
|
||||
}
|
||||
if(options.theme[2]){
|
||||
options.actived = options.theme[2]
|
||||
}
|
||||
}
|
||||
function init(){
|
||||
$player = $('<div>').addClass('player')
|
||||
$progress = $('<span>').addClass('progress')
|
||||
$state = $('<span>').addClass('state').on('click',toggle)
|
||||
$title = $('<span>').addClass('title')
|
||||
$lyric = $('<span>').addClass('lyric').hide()
|
||||
$list = $('<ol>').addClass('list')
|
||||
$player.append($progress, $state, $title, $lyric)
|
||||
$('body').append($player)
|
||||
}
|
||||
function play(){
|
||||
if($jplayer){
|
||||
$jplayer.jPlayer('play')
|
||||
$state.addClass('playing')
|
||||
if($jplayer.jPlayer.hasLyric){
|
||||
$title.hide()
|
||||
$lyric.show()
|
||||
}
|
||||
}
|
||||
}
|
||||
function pause(){
|
||||
if($jplayer){
|
||||
$jplayer.jPlayer('pause')
|
||||
$state.removeClass('playing')
|
||||
if($jplayer.jPlayer.hasLyric){
|
||||
$title.show()
|
||||
$lyric.hide()
|
||||
$player.attr('title',$title.text())
|
||||
}
|
||||
}
|
||||
}
|
||||
function toggle(){
|
||||
$state.hasClass('playing') ? pause() : play()
|
||||
}
|
||||
})(window, document, jQuery)
|
||||
|
||||
BIN
MyPlayer/assets/swf/Jplayer.swf
Normal file
BIN
MyPlayer/assets/swf/Jplayer.swf
Normal file
Binary file not shown.
64
MyPlayer/player/index.html
Normal file
64
MyPlayer/player/index.html
Normal file
@@ -0,0 +1,64 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title></title>
|
||||
<meta charset="UTF-8" />
|
||||
<style type="text/css">
|
||||
html,body,div{
|
||||
padding:0;
|
||||
margin:0;
|
||||
font-size:12px;
|
||||
}
|
||||
.player{
|
||||
display:inline-block;
|
||||
position: relative;
|
||||
width:18em;
|
||||
height:2em;
|
||||
padding:0 .3em;
|
||||
line-height:2em;
|
||||
overflow: hidden;
|
||||
background:whitesmoke;
|
||||
}
|
||||
.player>.progress{
|
||||
display:inline-block;
|
||||
background:silver;
|
||||
position: absolute;
|
||||
left:0;
|
||||
top:0;
|
||||
height:2em;
|
||||
}
|
||||
.player>.state{
|
||||
position: absolute;
|
||||
left:0.6em;
|
||||
top:0.4em;
|
||||
width:0;
|
||||
height:0;
|
||||
border: .6em solid transparent;
|
||||
border-left: .9em solid black;
|
||||
border-right:none;
|
||||
cursor:pointer;
|
||||
}
|
||||
.player>.state.playing{
|
||||
border:.3em solid black;
|
||||
border-top:none;
|
||||
border-bottom:none;
|
||||
width:.3em;
|
||||
height:1.2em;
|
||||
}
|
||||
.player>.title, .player>.lyric{
|
||||
position: absolute;
|
||||
left:0;
|
||||
left:2em;
|
||||
display:inline-block;
|
||||
height:2em;
|
||||
cursor:default;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<script src="http://lib.sinaapp.com/js/jquery/1.10.2/jquery-1.10.2.min.js"></script>
|
||||
<script src="http://www.jplayer.org/latest/js/jquery.jplayer.min.js"></script>
|
||||
<script src="../assets/js/player.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user