[Userscript] Download nhạc 320kbps từ mp3 zing

  Bài viết hay nhất1
Userscript này sẽ cho phép bạn nghe và tải nhạc chất lượng cao từ mp3 zing, bao gồm các bài hát thu phí.

Demo


[You must be registered and logged in to see this image.]
Download bài hát

[You must be registered and logged in to see this image.]
Download album

Kiểm tra chất lượng:

Cài đặt


Dùng một trong các link sau:

  1. [You must be registered and logged in to see this link.]
  2. [You must be registered and logged in to see this link.]
  3. [You must be registered and logged in to see this link.]

Sau khi cài đặt, nhấp vào các liên kết bên dưới để kiểm tra:

  1. [You must be registered and logged in to see this link.]
  2. [You must be registered and logged in to see this link.]
  3. [You must be registered and logged in to see this link.]
  4. [You must be registered and logged in to see this link.]

Mã nguồn


Code:
// ==UserScript==
// @name        Download nhạc mp3 zing 320kbps
// @namespace    baivong.download.mp3zing
// @description  Nghe và tải nhạc nhất lượng cao 320kbps tại mp3.zing.vn
// @version      5.7.0
// @icon        http://i.imgur.com/PnF4UN2.png
// @author      Zzbaivong
// @license      MIT
// @match        http://mp3.zing.vn/*
// @require      https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js
// @require      https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/1.3.3/FileSaver.min.js
// @noframes
// @connect      zing.vn
// @connect      zadn.vn
// @connect      zdn.vn
// @supportURL  https://github.com/baivong/Userscript/issues
// @run-at      document-idle
// @grant        GM_xmlhttpRequest
// @grant        GM_addStyle
// ==/UserScript==

(function ($, window, document) {
    'use strict';

    /**
    * Cookie tài khoản VIP
    * 04/10/2017
    */
    var vipKey = 'miup.107493696.0.HpC1cghJzuNgwf-3gjFtXT_Hfbc9CFm2gxSKCFFJzuK';


    GM_addStyle('.bv-icon{background-image:url(http://static.mp3.zdn.vn/skins/zmp3-v4.1/images/icon.png)!important;background-repeat:no-repeat!important;background-position:-25px -2459px!important;}.bv-download{background-color:#721799!important;border-color:#721799!important;}.bv-download span{color:#fff!important;margin-left:8px!important;}.bv-disable,.bv-download:hover{background-color:#2c3e50!important;border-color:#2c3e50!important;}.bv-text{background-image:none!important;color:#fff!important;text-align:center!important;font-size:smaller!important;line-height:25px!important;}.bv-waiting{cursor:wait!important;background-color:#2980b9!important;border-color:#2980b9!important;}.bv-complete,.bv-complete:hover{background-color:#27ae60!important;border-color:#27ae60!important;}.bv-error,.bv-error:hover{background-color:#c0392b!important;border-color:#c0392b!important;}.bv-disable{cursor:not-allowed!important;opacity:0.4!important;}');

    function getCookie(name) {
        var cname = name + '=',
            cpos = document.cookie.indexOf(cname),
            cstart,
            cend;

        if (cpos !== -1) {
            cstart = cpos + cname.length;
            cend = document.cookie.indexOf(';', cstart);
            if (cend === -1) cend = document.cookie.length;
            return decodeURIComponent(document.cookie.substring(cstart, cend));
        }

        return null;
    }

    function setCookie(cname, cvalue, exdays, path) {
        var domain = '',
            d = new Date();

        if (exdays) {
            d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
            exdays = '; expires=' + d.toUTCString();
        }
        if (!path) path = '/';

        document.cookie = cname + '=' + cvalue + '; path=' + path + exdays + domain + ';';
    }

    function getParams(name, url) {
        if (!url) url = window.location.href;
        name = name.replace(/[\[\]]/g, '\\$&');
        var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
            results = regex.exec(url);
        if (!results) return null;
        if (!results[2]) return '';
        return decodeURIComponent(results[2].replace(/\+/g, ' '));
    }

    function setQuanlity(qty) {
        var $qtyStyle = $('#bv-quanlity-style');

        if (!$qtyStyle.length) $qtyStyle = $('<style />', {
            id: 'bv-quanlity-style',
            type: 'text/css'
        }).appendTo('head');

        $qtyStyle.text('.zm-quanlity-display{font-size:0!important}.zm-quanlity-display::after{content:"' + qty + '";font-size:12px!important}');
    }

    function albumCounter() {
        if (!enableAlbum) return;
        if (!$album.length) return;

        var temp = ++listCurr;
        if (temp === listSize) {
            $btnAll.removeClass('bv-waiting').addClass('bv-disable').off('click');
            $txtAll.text('Đã tải toàn bộ');
            return;
        }

        $txtAll.text('Đã tải ' + temp + '/' + listSize);

        if ($list.eq(temp).attr('href') !== '#download') {
            albumCounter();
            return;
        }
        multiDownloads($list.eq(temp));
    }

    function getData(callback, songCode) {
        var url = $('#zplayerjs-wrapper').data('xml'),
            key;

        if (songCode) {
            key = songCode;
            url = '/json/song/get-source/' + songCode;
        } else {
            key = getParams('key', url);
            url = 'http://mp3.zing.vn/xhr' + url;
        }

        if (cache[key]) {
            callback(cache[key]);
            return;
        }

        GM_xmlhttpRequest({
            method: 'GET',
            url: url,
            headers: {
                'Cookie': 'wsid=' + vipKey
            },
            responseType: 'json',

            onload: function (source) {
                var data = source.response.data;

                if (data) {
                    cache[key] = data;
                    callback(data);
                } else {
                    callback();
                }
            },

            onerror: function (e) {
                console.error(e);
                callback();
            }
        });
    }

    function downloadSong(url, name, progress, complete, error) {
        GM_xmlhttpRequest({
            method: 'GET',
            url: url,
            responseType: 'blob',

            onload: function (source) {
                complete(source.response, name + '.mp3');
                albumCounter();
            },

            onprogress: function (e) {
                if (e.lengthComputable) {
                    progress(Math.floor(e.loaded * 100 / e.total) + '%');
                } else {
                    progress('');
                }
            },

            onerror: function (e) {
                console.error(e);
                error();
                albumCounter();
            }
        });
    }

    function baiHat() {
        var $largeBtn = $('#tabService'),
            $btn = $('<a>', {
                class: 'button-style-1 pull-left bv-download',
                href: '#download',
                html: '<i class="zicon icon-dl"></i>'
            }),
            $txt = $('<span>', {
                text: 'Tải nhạc 320kbps'
            }),
            downloadFail = function () {
                $btn.removeClass('bv-waiting').addClass('bv-error');
                $txt.text('Lỗi! Không tải được');
            };

        $largeBtn.replaceWith($btn.append($txt));

        getData(function (data) {
            if (data && data.source && data.source['320']) {
                $('#zplayerjs').attr('src', data.source['320']);
                setQuanlity('320kbps');

                $btn.attr({
                    'data-name': data.link.match(/^\/bai-hat\/([^\/]+)/)[1],
                    'data-mp3': data.source['320']
                });
            } else {
                setQuanlity('128kbps');

                downloadFail();
                return;
            }
        });

        $btn.one('click', function (e) {
            e.preventDefault();

            $btn.addClass('bv-waiting');
            $txt.text('Chờ một chút...');

            downloadSong(
                $btn.data('mp3'),
                $btn.data('name'),
                function (percent) {
                    $txt.text('Đang tải... ' + percent);
                },
                function (blob, fileName) {
                    $btn.attr({
                        href: window.URL.createObjectURL(blob),
                        download: fileName
                    }).removeClass('bv-waiting').addClass('bv-complete').off('click');
                    $txt.text('Nhấn để tải nhạc');

                    saveAs(blob, fileName);
                },
                function () {
                    downloadFail();
                }
            );
        });
    }

    function multiDownloads($btn) {
        $btn.addClass('bv-waiting bv-text').text('...').attr({
            href: '#downloading'
        });

        downloadSong(
            $btn.data('mp3'),
            $btn.data('name'),
            function (percent) {
                if (percent !== '') {
                    $btn.text(percent);
                }
            },
            function (blob, fileName) {
                $btn.attr({
                    href: window.URL.createObjectURL(blob),
                    download: fileName
                }).removeClass('bv-waiting bv-text').addClass('bv-complete').text('').off('click');

                saveAs(blob, fileName);
            },
            function () {
                $btn.removeClass('bv-waiting bv-text').addClass('bv-error').text('');
            }
        );
    }

    function album() {
        getData(function (data) {
            var playlist = window.eval('window.playlist;'),
                download = function (e) {
                    e.preventDefault();
                    multiDownloads($(this));
                };

            if (!(data && data.items)) return;
            setQuanlity('320kbps');

            $album.find('.fn-dlsong').each(function (i, v) {
                if (data.items[i] && data.items[i].source && data.items[i].source['320']) {
                    playlist[i].sourceLevel[0].source = data.items[i].source['320'];
                    $(v).replaceWith('<a title="Tải nhạc 320kbps" class="bv-download bv-album-download bv-icon" href="#download" data-name="' + data.items[i].link.match(/^\/bai-hat\/([^\/]+)/)[1] + '" data-mp3="' + data.items[i].source['320'] + '"></a>');
                }
            });

            window.eval('var disableRePlaying; player2.on("play", function (){ if (!disableRePlaying) { $(".fn-name", ".playing.fn-current").click(); disableRePlaying = true; } });');

            $btnAll = $('<a>', {
                class: 'button-style-1 pull-left bv-download',
                href: '#download-album',
                html: '<i class="zicon icon-dl"></i>'
            });
            $txtAll = $('<span>', {
                text: 'Tải toàn bộ'
            });
            $btnAll.append($txtAll).insertAfter('#tabAdd');

            if (!checkList()) return;

            $list.on('contextmenu', function (e) {
                e.preventDefault();
                var $this = $(this),
                    href = $this.attr('href');

                if (href === '#download') {
                    $this.addClass('bv-disable').attr({
                        href: '#download-disabled',
                    }).off('click', download);
                } else if (href === '#download-disabled') {
                    $this.removeClass('bv-disable').attr({
                        href: '#download',
                    }).one('click', download);
                }
            }).one('click', download);

            $btnAll.one('click', function (e) {
                e.preventDefault();

                if (!checkList()) {
                    $btnAll.addClass('bv-error').off('click');
                    $txtAll.text('Không có nhạc cần tải');
                    return;
                }

                enableAlbum = true;
                $btnAll.addClass('bv-waiting');
                $txtAll.text('Đang tải...');

                $list.off('click');

                listCurr = 0;
                multiDownloads($list.eq(listCurr));
            });
        });
    }

    function video() {
        var videoPlay = function (qty) {
            getData(function (data) {
                if (data && data.source && data.source[qty]) {
                    window.eval('player2.setSource("' + data.source[qty] + '");');
                } else {
                    console.warn(data);
                }

                setCookie('videoQuanlity', qty, 30, '/');
                setQuanlity(qty);
            });
        }

        if (getCookie('videoQuanlity') !== null) videoPlay(getCookie('videoQuanlity'));

        $(document).on('click', '.zm-list-quanlity li', function (e) {
            e.preventDefault();
            var qty = this.textContent.replace('(VIP)', '').trim();

            videoPlay(qty);
        });
    }

    function checkPath(key) {
        return (location.pathname.indexOf('/' + key + '/') === 0);
    }


    window.URL = window.URL || window.webkitURL;
    var cache = [];

    window.eval('zmp3Login._show = zmp3Login.show; zmp3Login.show = function (){ return; }; $(".fn-login").on("click", zmp3Login._show);');

    if (checkPath('bai-hat')) baiHat();
    if (checkPath('video-clip')) video();

    var $album = $('#playlistItems'),
        $btnAll,
        $txtAll,
        $list,
        listCurr = 0,
        listSize = 0,
        checkList = function () {
            $list = $album.find('.bv-album-download[href="#download"]');
            listSize = $list.length;

            return listSize > 0;
        },
        enableAlbum;
    if (checkPath('album') || checkPath('playlist')) album();

    $(document).on('mouseenter', 'li[data-code]', function (e) {
        e.preventDefault();
        var $this = $(this),
            $btn = $this.find('.fn-dlsong');

        if ($this.closest('#playlistItems').length) return;
        if ($this.data('code') === '') return;
        if (!$btn.length) return;

        $btn.replaceWith(function () {
            return '<a title="Tải nhạc 320kbps" class="bv-download bv-multi-download bv-icon" href="#download" data-code="' + $this.data('code') + '"></a>';
        });
    }).on('click', '.bv-multi-download', function (e) {
        e.preventDefault();
        var $this = $(this);

        getData(function (data) {
            if (data && data[0].source_list && data[0].source_list.length >= 2 && data[0].source_list[1] !== '') {
                $this.attr({
                    'data-name': data[0].link.match(/^\/bai-hat\/([^\/]+)/)[1],
                    'data-mp3': data[0].source_list[1]
                });
                multiDownloads($this);
            } else {
                $this.removeClass('bv-waiting bv-text').addClass('bv-error').text('');
            }
        }, $this.data('code'));
    });

})(jQuery, window, document);

Hướng dẫn


Chỉ có tuỳ chọn nghe và tải xuống duy nhất là 320kbps, với những bài có chất lượng thấp hơn sẽ không tải được.
Những vị trí tải được thì khi rê chuột lên sẽ hiện nút tải xuống màu tím.
Khi dùng chức năng tải toàn bộ trong album, nếu không muốn tải xuống bài nào, thì nhấp chuột phải nên nút tải của bài đó, để vô hiệu hoá nó.

Một số trang cho phép tải nhạc chất lượng cao khác.

  • CSN : [You must be registered and logged in to see this link.]
  • NhacPro : [You must be registered and logged in to see this link.]
  • Youtube : Xem hướng dẫn Tải nhạc MP3 từ Youtube dùng Youtube-DL và Firefox

Tags: [You must be registered and logged in to see this link.]
  Bài viết hay nhất2
hay đó huynh - đở phải coppy địa chỉ thay vào như trước, trò này k biết bao lâu thì bị chặn nữa @@
  Bài viết hay nhất3
cho em hỏi ngu !! .. nhạc 320kb khác gì so với 240kb v bác baivong ??
  Bài viết hay nhất4
[You must be registered and logged in to see this link.]
KaiJit_GC wrote:cho em hỏi ngu !! .. nhạc 320kb khác gì so với 240kb v bác baivong ??
Chính xác thì sẽ viết là 320Kbps/s đây mới là chuẩn của nhạc mp3, 128Kbps/s là đã rút gọn lại rồi và ở mức chấp nhận được thôi chứ 320Kbps/s mới là chuẩn đúng, tuy nhiên để có thể phân biệt rõ sự khác biệt thì bài hát đó phải lấy từ bài hát thu từ gốc convert ra chứ convert nhạc từ 128Kbps lên 320Kbps thì sẽ không có sự khác biệt vẫn chỉ là 128Kbps mà thôi, thứ 2 để có thể thấy rõ chất lượng giữa 320Kbps và 128Kbps (đều từ bản nhạc gốc convert sang) thì bạn cần có tai nghe loại xịn, hoặc dàn âm thanh xịn thì mới thấy sự khác biệt các tai nghe dưới 100k hoặc loa + amply bình thường thì không thấy khác gì đâu vì nó không tái hiện được âm thanh đúng chuẩn 320Kbps.
The author of this message was banned from the forum - See the message
  Bài viết hay nhất6
[You must be registered and logged in to see this link.]
Gang wrote:dán code thế nào anh?
[You must be registered and logged in to see this link.]
The author of this message was banned from the forum - See the message
  Bài viết hay nhất8
[You must be registered and logged in to see this link.]
Gang wrote:chèn tiện ích rồi...

Đọc kĩ phần cài đặt
Cài đặt: userscripts.org đang lỗi nên mình chưa tải lên được, bạn dùng chức năng tạo file userscript và dán code vào.
The author of this message was banned from the forum - See the message
  Bài viết hay nhất10
Like nè like nè like mạnh luôn nè :v
Từ giờ xóa hết nhạc đã tải rồi tải lại mới được =))
The author of this message was banned from the forum - See the message
  Bài viết hay nhất12
[You must be registered and logged in to see this link.]
Gang wrote:chắc chắn là dung lượng lớn 1 chút nhưng ko sao,,,chất lượng nó hay là đc rồi
có tiện ích nào cho nhaccuatui, nhacso hay tất cả các trang nhạc khác ko?

có cái gì thì dùng cái nấy đi - đừng đòi hỏi

@NCat : tình hình là số lượng bài hát có chất lượng chuẩn 320 trên mp3 k phải là tất cả, chỉ có 1 số bài thôi - còn lại vẫn có rất nhiều bài đầu ra vẫn chỉ 128 @@ - Khuyên k nên xoá hết các bài củ, mà hãy tải những bài chuẩn chất lượng sau đó Dán vào folder nhạc của mình bài nào trùng thì thay thế hết, như thế vừa k mất nhạc củ mà vừa update nhạc 128 lên 320 :v
  Bài viết hay nhất13
Errr mà thẻ nhớ máy méo không cho phép quá nhiều, chắc để tải về máy rồi gắn tai nghe thôi =))
  Bài viết hay nhất14
Cập nhật ver 1.0, cho phép tải từ trang nghệ sĩ #1
  Bài viết hay nhất15
Ảo :v Có vẻ hay :3 Nếu có nct thì hóng
  Bài viết hay nhất16
Bác "Hóng" fan Hồ Quang Hiếu hả :fb163:
  Bài viết hay nhất17
Hướng dẫn thêm cho người dùng chrome ngoài net khỏi cài thêm lung tung thì chỉ cần tải cái này về , xong vào chrome://extensions/ check vào ô
Chế độ dành cho nhà phát triển ở góc trên bên phải xong lôi file này thả vào rồi vào zingmp3 down 320 bình thường .
The author of this message was banned from the forum - See the message
  Bài viết hay nhất19
Ở nct nó có cho down nhạc 320k thì phải, em down bài nào cũng ~ từ 10mb - 15mb :fb184:
  Bài viết hay nhất20
Lạc đề nhé, ở đây là mình hướng dẫn cách để bạn download ở mp3 zing.
Nếu cần nhạc 320kbs thì không thiếu trang để download, ví dụ: nhac.vui.vn và nhacso.net - 2 trang này sắp xếp nhạc rất gọn gàng, chỉ cần đăng ký là được, còn trang chiasenhac.com thậm chí còn cho bạn download cả nhạc Lossless.
  Bài viết hay nhất21
Nhưng có một số bất cập là có một số bài không có ở các trang khác mà mp3 zing lại có nên cái userscript này mới ra đời đúng không huynh Vống :v
Err mà cái trang chiasenhac tốt đấy huynh :v giờ méo mới biết :3
  Bài viết hay nhất22
[You must be registered and logged in to see this link.]
NCat wrote:Nhưng có một số bất cập là có một số bài không có ở các trang khác mà mp3 zing lại có nên cái userscript này mới ra đời đúng không huynh Vống :v
Err mà cái trang chiasenhac tốt đấy huynh :v giờ méo mới biết :3
Lúc làm thì ad không có dự tính gì, mà đúng là có một số bài hát mà zing mp3 mua bản quyền thì mấy trang khác không có, hoặc có trễ hơn.
  Bài viết hay nhất23
Giờ cái điên tiết là bên zing nó hâm hấp để kiểu lúc tìm thì ra cái bài đó, nhưng lúc mở ra thì nó báo là bị xóa do bên bản quyền :v Có cách nào khắc phục không huynh :-s
  Bài viết hay nhất24
Bó tay, tìm nguồn khác chứ sao :v
  Bài viết hay nhất25
[You must be registered and logged in to see this link.]
anhoang_qn wrote:
Chính xác thì sẽ viết là 320Kbps/s đây mới là chuẩn của nhạc mp3, 128Kbps/s là đã rút gọn lại rồi và ở mức chấp nhận được thôi chứ 320Kbps/s mới là chuẩn đúng

320 Kilobite per second = 320 Kb/s = Mỗi một giây tải được 320 kilô bit rồi còn chèn /s vào làm gì.  128Kbps là chât lượng thuộc zạng đã nén. Chuẩn này trươc đây sử zụng cho VCD nén MP3 để được nhiều bài hat hơn. Zung lượng ít nhât là jảm đi một nửa sau khi nén.

KaiJit_GC wrote:cho em hỏi ngu !! .. nhạc 320kb khác gì so với 240kb v bác baivong ??

Có thể nge ví dụ về nhạc 320kbps tại đây

[You must be registered and logged in to see this link.]
You cannot reply to topics in this forum