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

  Bài viết hay nhất1
First topic message reminder :

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ấ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.]
  Bài viết hay nhất26
anh vong ơi, anh có thể phát triển nó lên down nhạc Lossless được ko, em thích nhạc EDM lém nhưng phải nghe chất lượng cao mới thích cơ, anh cố gắng phát triển nhé

Anh thích nghe nhạc lém hả bác vong?
  Bài viết hay nhất27
Không lên được nhé bạn. MP3Zing nó up lên tối đa thế nào thì mình chỉ lách luật kéo xuống được thế này thôi, không hơn không kém được đâu. Lossless thì chắc bạn dân hạng sang rồi, mình dân siđa nên chỉ nghe 320 thôi :\
  Bài viết hay nhất28
Giờ cái này hết tác dụng ròi T_T
  Bài viết hay nhất29
Cái này xài co Zing bản cũ bạn nhé. Sử dụng bản mới đây: [You must be registered and logged in to see this link.]
  Bài viết hay nhất30
Cập nhật: Sửa lỗi không tải được nhạc sau khi Zing mp3 nâng cấp phiên bản 4.
  Bài viết hay nhất31
Cập nhật v5.1.0: Tải trung gian qua Linksvip do Zing Mp3 đã chặn quyền truy cập API tải nhạc.
  Bài viết hay nhất32
Cập nhật v5.2.0: Tải trung gian qua Linksvip, bỏ qua popup chuyển hướng.
  Bài viết hay nhất33
Cập nhật v5.2.1:

  • Bổ sung tiến trình tải.
  • Lưu vào bộ nhớ đệm, giảm tải cho server.
  Bài viết hay nhất34
Cập nhật v5.2.2:

  • Sửa lỗi mất tên khi tải ngoài bài hát đơn.
  • Cập nhật chức năng download 320kbps cho các khu vực bị thiếu, trừ Realtime.

Cập nhật v5.2.3:

  • Sửa lỗi mất nút tải bài hát đơn sau khi click.

Cập nhật v5.3.0:

  • Thêm chức năng tải toàn bộ album.

Cập nhật v5.3.1:

  • Báo lỗi khi không lấy được nhạc 320kbps.
  Bài viết hay nhất35
v5.4.0

  • Ngừng truyền tải qua LinksVIP do lỗi kết nối.
  • Sử dụng tài khoản VIP, hạn dùng 04/10/2017.
  Bài viết hay nhất36
v5.5.0

  • Hỗ trợ nghe nhạc chất lượng 320kbps trong bài hát đơn (nếu có).

v5.6.0

  • Viết lại mã nguồn.

v5.6.1

  • Hỗ trợ nghe nhạc chất lượng 320kbps trong album (nếu có).

v5.6.2

  • Cho phép kích hoạt/vô hiệu hoá tải bài hát, trong chế độ Tải toàn bộ.
  • Sửa lỗi vô hiệu hoá nút chọn chất lượng video.

v5.7.0

  • Sửa lỗi trong Bài hátAlbum do Zing Mp3 cập nhật.
  • Thêm chức năng xem MV chất lượng cao.
You cannot reply to topics in this forum