magentamusik stream url

get magentamusik stream url with just one click

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         magentamusik stream url
// @namespace    http://tampermonkey.net/
// @version      2
// @description  get magentamusik stream url with just one click
// @author       mihau
// @match        https://www.magentamusik.de/*
// @exclude        https://www.magentamusik.de/
// @exclude        https://www.magentamusik.de/collection/*
// @supportURL   https://greasyfork.org/en/scripts/551875-magentamusik-stream-url
// @license MIT
// ==/UserScript==

// from https://stackoverflow.com/questions/5525071/how-to-wait-until-an-element-exists
function waitforit(selector) {
  return new Promise(resolve => {
    if (document.querySelector(selector)) {
      return resolve(document.querySelector(selector));
    }

    var observer = new MutationObserver(mutations => {
      if (document.querySelector(selector)) {
        observer.disconnect();
        resolve(document.querySelector(selector));
      }
    });

    // If you get "parameter 1 is not of type 'Node'" error, see https://stackoverflow.com/a/77855838/492336
    observer.observe(document.body, { childList: true, subtree: true });
  });
}


var xhr = new XMLHttpRequest();
var a, b, c;

waitforit('.sc-17yqz66-0.dbUgKs').then((elm) => {
 
$qa = function(_) {return document.querySelectorAll(_)}

var
_ = "https://wcps.t-online.de/cvss/magentamusic/vodclient/v2/assetdetails/58938/DMM_MOVIE_",
                                                                       // ^^^^^ // hardcoded, kann sich also jederzeit ändern
movieid = "",
prfx = "[data-js-element=",
live = "'o-main-stage__config']",
arch = "'o-video-player__config']",
dmm = /DMM_MOVIE_(.*?)"/;
  
       if ($qa(prfx+live)[0]) {
  movieid = $qa(prfx+live)[0].innerText.match(dmm)[1];
} else if ($qa(prfx+arch)[0]) {
  movieid = $qa(prfx+arch)[0].innerText.match(dmm)[1];
} else {
  var loc = window.location.pathname.split('-');
  movieid = loc[loc.length - 1];
}
  
var getJSON = function(url, callback) {

  xhr.open('GET', url, true);
  xhr.responseType = 'json'; 

  xhr.onload = function() {

    var status = xhr.status;

    if (status == 200) {
      callback(null, xhr.response);
    } else {
      callback(status);
    }
  };

  xhr.send();
};

getJSON(_ + movieid, function(err, data) {

  if (err != null) {
    console.error(err);
  } else {
    a = data.content.partnerInformation[0].features[0].player.href;
    getJSON(a, function(err, data) {
      if (err != null) {
        console.error(err);
      } else {

        b = data.content.feature.representations[0].contentPackages[0].media.href;
        xhr.open("GET", b);

        xhr.responseType = "document";
        xhr.overrideMimeType("text/xml");

        xhr.onload = () => {
          if (xhr.readyState === xhr.DONE && xhr.status === 200) {

            // document.title = "[!] " + document.title;
              
              c = xhr.responseXML.getElementsByTagName("media")[0].getAttribute("src");
              
              var logo = document.getElementsByClassName("o-header__trigger")[0].innerHTML;
              document.getElementsByClassName("o-header__trigger")[0].innerHTML = '<a id="m3u8" href="#" style="font-size:30px; text-decoration:none">&#x1f847;</a> ' + logo;
              document.getElementsByClassName("o-header__trigger")[0].onclick = function() {showURL(c);event.preventDefault()};

          }
        };

        xhr.send();

      }
    });

  }
});

if ($qa(".m-mixed-copy__toggle")[0]) {
  $qa(".m-mixed-copy__toggle")[0].click();
  $qa(".m-mixed-copy__toggle")[0].style.display="none";
  $qa(".m-mixed-copy__toggle")[0].style.visibility="hidden";
}
  
});

function showURL() {
  // console.log(xhr.response)
  // alert (a+"\n\n"+b+"\n\n"+c);
  var test = prompt("stream URL (OK for ffmpeg command)", c);
  if (test !== null) {
    prompt("ffmpeg command (OK for AUDIO-ONLY command)", 'ffmpeg -referer "' + location.href + '" -user_agent "' + window.navigator.userAgent + '" -i "' + c + '" -c copy -bsf:a aac_adtstoasc "' + location.pathname.replace(/\//, "") + '.mp4"');
    if (test !== null) {
      prompt("ffmpeg AUDIO-ONLY command", 'ffmpeg -referer "' + location.href + '" -user_agent "' + window.navigator.userAgent + '" -i "' + c + '" -vn -c:a copy "' + location.pathname.replace(/\//, "") + '-audio.m4a"');
    }
  }

}