// SPDX-License-Identifier: BSD-3-Clause
/**
* Copyright (c) 2021 kXuan. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
* following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following
* disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#define _GNU_SOURCE
#include <dlfcn.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
#include <vlc/vlc.h>
#include <vlc/plugins/vlc_common.h>
#include <vlc/plugins/vlc_stream.h>
static void *load_sym(void *override_func, const char *name)
{
void *ptr = dlsym(RTLD_NEXT, name);
if (ptr == NULL) {
fprintf(stderr, "Cannot load symbol '%s' %s. Please report bug on AUR.\n", name, dlerror());
exit(1);
}
if (ptr == override_func) {
fprintf(stderr, "circular reference '%s'. Please report bug on AUR.\n", name);
exit(1);
}
return ptr;
}
static int is_flac(const char *url)
{
static const char suffix[] = ".flac";
if (!url) {
return 0;
}
size_t len = strlen(url);
if (len < sizeof(suffix)) {
return 0;
}
return strcasecmp(url + len - sizeof(suffix) + 1, suffix) == 0;
}
/**
* The netease cloud music server set the Content-Type of .flac format to mpeg/audio, which results vlc unable to decode
* the music and play.
*
* To make vlc works correctly, we rewrite the Content-Type to audio/flac.
*
* @param s
* @param query
* @param args
* @return
*/
int vlc_stream_vaControl(stream_t *s, int query, va_list args)
{
static typeof(vlc_stream_vaControl) *orig_fn;
if (orig_fn == NULL) {
orig_fn = load_sym(vlc_stream_vaControl, __func__);
}
if (query == STREAM_GET_CONTENT_TYPE && is_flac(s->psz_url)) {
*va_arg(args, char **) = strdup("audio/flac");
return VLC_SUCCESS;
} else {
return orig_fn(s, query, args);
}
}
struct string_with_len {
const char *s;
size_t len;
};
#define STRING_WITH_LEN_INIT(s) {s, sizeof(s)-1}
/**
* drop all library fixes.
*
* Library fixes should only be applied to the netease-cloud-music main process. Sometime, netease-cloud-music execute
* external program, such as `xdg-open`, `kde-open5`. Those external programs use newer version qt and other new
* libraries. If we don't drop these environment variables, those programs may not work, because some symbol may not
* exist in the bundled old library.
*
* @param path
* @param argv
* @param envp
* @return
*/
int execve(const char *path, char *const argv[], char *const envp[])
{
static typeof(execve) *orig_fn;
if (orig_fn == NULL) {
orig_fn = load_sym(execve, "execve");
}
static struct string_with_len drop_env[] = {
STRING_WITH_LEN_INIT("LD_LIBRARY_PATH="),
STRING_WITH_LEN_INIT("LD_PRELOAD="),
STRING_WITH_LEN_INIT("QT_PLUGIN_PATH="),
STRING_WITH_LEN_INIT("QT_QPA_PLATFORM_PLUGIN_PATH="),
STRING_WITH_LEN_INIT("QT_QPA_PLATFORM="),
};
size_t nenv;
for (nenv = 0; envp[nenv]; nenv++);
char *new_envp[nenv + 1];
char *const *src = envp;
char **dst = new_envp;
while (*src) {
for (int i = 0; i < sizeof(drop_env) / sizeof(*drop_env); ++i) {
if (strncmp(drop_env[i].s, *src, drop_env[i].len) == 0) {
goto next_env;
}
}
*dst = *src;
++dst;
next_env:
++src;
}
*dst = NULL;
return orig_fn(path, argv, new_envp);
}
Ubuntu22.04安装网易云音乐
需积分: 0 86 浏览量
更新于2023-11-21
收藏 99.69MB ZIP 举报
在Ubuntu 22.04操作系统中安装网易云音乐的过程涉及一些步骤,因为这款音乐软件并未在官方软件库中提供。然而,用户可以通过其他方法来安装。以下是一种常见且安全的安装方法,适用于那些喜欢使用网易云音乐享受音乐的Ubuntu用户。
我们需要确保系统已经更新到最新状态。打开终端(Terminal)并输入以下命令:
```bash
sudo apt update
sudo apt upgrade
```
接下来,由于网易云音乐是基于Deb格式的软件包,我们可以直接通过dpkg命令进行安装。但是,由于该软件包可能依赖于一些Ubuntu 22.04中未包含的库,所以我们需要先安装依赖。下载`netease-cloud-music_1.2.1_amd64_ubuntu_20190428.deb`文件,如果没有的话,可以去网易云音乐官网或者第三方资源站点寻找适合Ubuntu 22.04的版本。
下载完成后,使用以下命令安装依赖:
```bash
sudo apt install -f
```
这将尝试安装任何缺失的依赖。然后,使用dpkg命令安装网易云音乐:
```bash
sudo dpkg -i netease-cloud-music_1.2.1_amd64_ubuntu_20190428.deb
```
如果在此过程中遇到任何依赖问题,可以使用apt-get解决它们:
```bash
sudo apt-get install -f
```
如果一切顺利,网易云音乐应该已经成功安装在你的Ubuntu 22.04系统上。可以在应用程序启动器中找到它,然后愉快地听歌了。
然而,有时可能会遇到旧版软件包与新系统不兼容的问题。在这种情况下,可以考虑使用Snap包,这是一个跨平台的软件包管理系统,能自动处理依赖关系。要在Ubuntu 22.04上通过Snap安装网易云音乐,只需执行:
```bash
sudo snap install --devmode --beta netease-cloud-music
```
这样,即使官方没有提供Ubuntu 22.04的专用版本,也能确保安装的是最新版本的网易云音乐。
至于提供的`patch.c`文件,通常这是用于对源代码进行修改的补丁文件。在本例中,可能是一个用于修正网易云音乐在Ubuntu 22.04上的兼容性问题的补丁。不过,直接应用这个补丁需要编译源代码,一般用户可能不会操作。如果遇到软件运行问题,可以尝试查找社区提供的相关补丁或解决方案。
安装网易云音乐在Ubuntu 22.04上虽然需要额外的步骤,但通过dpkg和Snap包管理工具,可以轻松完成。同时,理解如何处理依赖和应用补丁对于Linux用户来说是非常有用的技能。