vlos.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. 'use strict';
  2. export default {getMedia};
  3. function getMedia(vlosScript: string, seasonTitle: string, seasonNumber: string): IEpisodePage
  4. {
  5. let vlosMedia: IVlosScript;
  6. function f(script: string) {
  7. /* We need to scope things */
  8. /* This is what will give us the medias */
  9. function VilosPlayer() {
  10. this.load = function(a: string, b: any, c: any)
  11. {
  12. vlosMedia = this.config.media;
  13. vlosMedia.series = this.config.analytics.media_reporting_parent;
  14. };
  15. this.config = {};
  16. this.config.player = {};
  17. this.config.player.pause_screen = {};
  18. this.config.language = '';
  19. }
  20. /* Let's stub what the script need */
  21. const window = {
  22. WM: {
  23. UserConsent: {
  24. getUserConsentAdvertisingState(): string { return ''; }
  25. }
  26. }
  27. };
  28. const document = {
  29. getElementsByClassName(a: any): any { return {length: 0}; },
  30. };
  31. const localStorage = {
  32. getItem(a: any): any { return null; },
  33. };
  34. const $ = {
  35. cookie(a: any) { /* nothing */ },
  36. };
  37. /*
  38. Evil ugly things. Need to run the script from a somewhat untrusted source.
  39. Need to find a better way of doing.
  40. */
  41. // tslint:disable-next-line:no-eval
  42. eval(script);
  43. }
  44. f(vlosScript);
  45. if (vlosMedia === undefined)
  46. {
  47. console.error('Error fetching vlos data - aborting - Please report the error if happen again.');
  48. process.exit(-1);
  49. }
  50. return {
  51. episode: vlosMedia.metadata.episode_number,
  52. id: vlosMedia.metadata.id,
  53. series: vlosMedia.series.title,
  54. season: seasonTitle,
  55. title: vlosMedia.metadata.title,
  56. swf: '',
  57. volume: seasonNumber,
  58. filename: '',
  59. media: vlosMedia,
  60. };
  61. }