dasha 4.0.0-alpha.6 → 4.0.0-alpha.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/dasha.cjs CHANGED
@@ -795,14 +795,23 @@ const pipe = (...fns) => (value) => fns.reduce((acc, fn) => fn(acc), value);
795
795
 
796
796
  //#endregion
797
797
  //#region lib/dash/dash-extractor.ts
798
- const getStreamInfoByCodecs = (codecs) => {
799
- const videoCodec = tryParseVideoCodec(codecs);
800
- if (videoCodec) return new VideoStreamInfo({ codec: videoCodec });
801
- const audioCodec = tryParseAudioCodec(codecs);
802
- if (audioCodec) return new AudioStreamInfo({ codec: audioCodec });
803
- const subtitleCodec = tryParseSubtitleCodec(codecs);
804
- if (subtitleCodec) return new SubtitleStreamInfo({ codec: subtitleCodec });
805
- return new VideoStreamInfo();
798
+ const createMediaStreamInfo = (params) => {
799
+ const codecs = params.contentType === "text" && !params.mimeType?.includes("mp4") ? params.mimeType?.split("/")[1] : params.codecs;
800
+ if (!params.codecs && codecs) params.codecs = codecs;
801
+ if (params.codecs) {
802
+ const videoCodec = tryParseVideoCodec(params.codecs);
803
+ if (videoCodec) return new VideoStreamInfo({ codec: videoCodec });
804
+ const audioCodec = tryParseAudioCodec(params.codecs);
805
+ if (audioCodec) return new AudioStreamInfo({ codec: audioCodec });
806
+ const subtitleCodec = tryParseSubtitleCodec(params.codecs);
807
+ if (subtitleCodec) return new SubtitleStreamInfo({ codec: subtitleCodec });
808
+ } else {
809
+ const type = params.contentType || params.mimeType?.split("/")[0];
810
+ if (type === "video") return new VideoStreamInfo();
811
+ if (type === "audio") return new AudioStreamInfo();
812
+ if (type === "text") return new SubtitleStreamInfo();
813
+ }
814
+ throw new Error("Unable to determine the type of a track, cannot continue...");
806
815
  };
807
816
  const selectNonEmpty = (args) => {
808
817
  for (const element of args.elements) {
@@ -847,7 +856,7 @@ var DashExtractor = class DashExtractor {
847
856
  this.#baseUrl = this.#parserConfig.baseUrl ?? this.#mpdUrl;
848
857
  }
849
858
  #extendBaseUrl(node, baseUrl) {
850
- const target = node.getElementsByTagName("BaseURL")[0];
859
+ const target = node.getElementsByTagName("BaseURL").filter((n) => !!n.parentNode?.isSameNode(node))[0];
851
860
  if (target?.textContent) return combineUrl(baseUrl, target.textContent);
852
861
  return baseUrl;
853
862
  }
@@ -883,13 +892,15 @@ var DashExtractor = class DashExtractor {
883
892
  for (const adaptationSet of adaptationSets) {
884
893
  segBaseUrl = this.#extendBaseUrl(adaptationSet, segBaseUrl);
885
894
  const representationsBaseUrl = segBaseUrl;
886
- let mimeType = adaptationSet.getAttribute("contentType") || adaptationSet.getAttribute("mimeType");
895
+ let contentType = adaptationSet.getAttribute("contentType");
896
+ let mimeType = adaptationSet.getAttribute("mimeType");
887
897
  const frameRate = this.#getFrameRate(adaptationSet);
888
898
  const representations = adaptationSet.getElementsByTagName("Representation");
889
899
  for (const representation of representations) {
890
900
  segBaseUrl = this.#extendBaseUrl(representation, segBaseUrl);
891
- if (!mimeType) mimeType = representation.getAttribute("contentType") || representation.getAttribute("mimeType") || "";
892
- const codecParameterString = representation.getAttribute("codecs") || adaptationSet.getAttribute("codecs");
901
+ if (!contentType) contentType = representation.getAttribute("contentType");
902
+ if (!mimeType) mimeType = representation.getAttribute("mimeType");
903
+ const codecs = representation.getAttribute("codecs") || adaptationSet.getAttribute("codecs");
893
904
  const widthParameterString = representation.getAttribute("width");
894
905
  const heightParameterString = representation.getAttribute("height");
895
906
  const roles = getTagAttrs("Role", representation, adaptationSet);
@@ -897,7 +908,11 @@ var DashExtractor = class DashExtractor {
897
908
  const essentialProps = getTagAttrs("EssentialProperty", representation, adaptationSet);
898
909
  const accessibilities = getTagAttrs("Accessibility", representation, adaptationSet);
899
910
  const channelsString = getTagAttrs("AudioChannelConfiguration", adaptationSet, representation)[0]?.value;
900
- const streamInfo = getStreamInfoByCodecs(codecParameterString) ?? new VideoStreamInfo();
911
+ const streamInfo = createMediaStreamInfo({
912
+ codecs,
913
+ contentType,
914
+ mimeType
915
+ });
901
916
  const bitrate = Number(representation.getAttribute("bandwidth") ?? "");
902
917
  streamInfo.languageCode = this.#filterLanguage(representation.getAttribute("lang") || adaptationSet.getAttribute("lang"));
903
918
  if (streamInfo.type === "video") {
@@ -905,7 +920,7 @@ var DashExtractor = class DashExtractor {
905
920
  streamInfo.width = Number(widthParameterString);
906
921
  streamInfo.height = Number(heightParameterString);
907
922
  streamInfo.frameRate = frameRate || this.#getFrameRate(representation);
908
- if (supplementalProps && essentialProps) streamInfo.dynamicRange = parseDynamicRange(codecParameterString, supplementalProps, essentialProps);
923
+ if (supplementalProps && essentialProps) streamInfo.dynamicRange = parseDynamicRange(codecs, supplementalProps, essentialProps);
909
924
  } else if (streamInfo.type === "audio") {
910
925
  streamInfo.bitrate = bitrate;
911
926
  if (accessibilities) streamInfo.descriptive = checkIsDescriptive(accessibilities);
@@ -924,7 +939,7 @@ var DashExtractor = class DashExtractor {
924
939
  streamInfo.playlist.mediaParts.push(new MediaPart());
925
940
  streamInfo.periodId = periodId;
926
941
  streamInfo.groupId = representation.getAttribute("id");
927
- streamInfo.codecs = representation.getAttribute("codecs") || adaptationSet.getAttribute("codecs");
942
+ streamInfo.codecs = codecs;
928
943
  const volumeAdjust = representation.getAttribute("volumeAdjust");
929
944
  if (volumeAdjust) streamInfo.groupId = streamInfo.groupId + "-" + volumeAdjust;
930
945
  const mType = representation.getAttribute("mimeType") || adaptationSet.getAttribute("mimeType");
package/dist/dasha.mjs CHANGED
@@ -770,14 +770,23 @@ const pipe = (...fns) => (value) => fns.reduce((acc, fn) => fn(acc), value);
770
770
 
771
771
  //#endregion
772
772
  //#region lib/dash/dash-extractor.ts
773
- const getStreamInfoByCodecs = (codecs) => {
774
- const videoCodec = tryParseVideoCodec(codecs);
775
- if (videoCodec) return new VideoStreamInfo({ codec: videoCodec });
776
- const audioCodec = tryParseAudioCodec(codecs);
777
- if (audioCodec) return new AudioStreamInfo({ codec: audioCodec });
778
- const subtitleCodec = tryParseSubtitleCodec(codecs);
779
- if (subtitleCodec) return new SubtitleStreamInfo({ codec: subtitleCodec });
780
- return new VideoStreamInfo();
773
+ const createMediaStreamInfo = (params) => {
774
+ const codecs = params.contentType === "text" && !params.mimeType?.includes("mp4") ? params.mimeType?.split("/")[1] : params.codecs;
775
+ if (!params.codecs && codecs) params.codecs = codecs;
776
+ if (params.codecs) {
777
+ const videoCodec = tryParseVideoCodec(params.codecs);
778
+ if (videoCodec) return new VideoStreamInfo({ codec: videoCodec });
779
+ const audioCodec = tryParseAudioCodec(params.codecs);
780
+ if (audioCodec) return new AudioStreamInfo({ codec: audioCodec });
781
+ const subtitleCodec = tryParseSubtitleCodec(params.codecs);
782
+ if (subtitleCodec) return new SubtitleStreamInfo({ codec: subtitleCodec });
783
+ } else {
784
+ const type = params.contentType || params.mimeType?.split("/")[0];
785
+ if (type === "video") return new VideoStreamInfo();
786
+ if (type === "audio") return new AudioStreamInfo();
787
+ if (type === "text") return new SubtitleStreamInfo();
788
+ }
789
+ throw new Error("Unable to determine the type of a track, cannot continue...");
781
790
  };
782
791
  const selectNonEmpty = (args) => {
783
792
  for (const element of args.elements) {
@@ -822,7 +831,7 @@ var DashExtractor = class DashExtractor {
822
831
  this.#baseUrl = this.#parserConfig.baseUrl ?? this.#mpdUrl;
823
832
  }
824
833
  #extendBaseUrl(node, baseUrl) {
825
- const target = node.getElementsByTagName("BaseURL")[0];
834
+ const target = node.getElementsByTagName("BaseURL").filter((n) => !!n.parentNode?.isSameNode(node))[0];
826
835
  if (target?.textContent) return combineUrl(baseUrl, target.textContent);
827
836
  return baseUrl;
828
837
  }
@@ -858,13 +867,15 @@ var DashExtractor = class DashExtractor {
858
867
  for (const adaptationSet of adaptationSets) {
859
868
  segBaseUrl = this.#extendBaseUrl(adaptationSet, segBaseUrl);
860
869
  const representationsBaseUrl = segBaseUrl;
861
- let mimeType = adaptationSet.getAttribute("contentType") || adaptationSet.getAttribute("mimeType");
870
+ let contentType = adaptationSet.getAttribute("contentType");
871
+ let mimeType = adaptationSet.getAttribute("mimeType");
862
872
  const frameRate = this.#getFrameRate(adaptationSet);
863
873
  const representations = adaptationSet.getElementsByTagName("Representation");
864
874
  for (const representation of representations) {
865
875
  segBaseUrl = this.#extendBaseUrl(representation, segBaseUrl);
866
- if (!mimeType) mimeType = representation.getAttribute("contentType") || representation.getAttribute("mimeType") || "";
867
- const codecParameterString = representation.getAttribute("codecs") || adaptationSet.getAttribute("codecs");
876
+ if (!contentType) contentType = representation.getAttribute("contentType");
877
+ if (!mimeType) mimeType = representation.getAttribute("mimeType");
878
+ const codecs = representation.getAttribute("codecs") || adaptationSet.getAttribute("codecs");
868
879
  const widthParameterString = representation.getAttribute("width");
869
880
  const heightParameterString = representation.getAttribute("height");
870
881
  const roles = getTagAttrs("Role", representation, adaptationSet);
@@ -872,7 +883,11 @@ var DashExtractor = class DashExtractor {
872
883
  const essentialProps = getTagAttrs("EssentialProperty", representation, adaptationSet);
873
884
  const accessibilities = getTagAttrs("Accessibility", representation, adaptationSet);
874
885
  const channelsString = getTagAttrs("AudioChannelConfiguration", adaptationSet, representation)[0]?.value;
875
- const streamInfo = getStreamInfoByCodecs(codecParameterString) ?? new VideoStreamInfo();
886
+ const streamInfo = createMediaStreamInfo({
887
+ codecs,
888
+ contentType,
889
+ mimeType
890
+ });
876
891
  const bitrate = Number(representation.getAttribute("bandwidth") ?? "");
877
892
  streamInfo.languageCode = this.#filterLanguage(representation.getAttribute("lang") || adaptationSet.getAttribute("lang"));
878
893
  if (streamInfo.type === "video") {
@@ -880,7 +895,7 @@ var DashExtractor = class DashExtractor {
880
895
  streamInfo.width = Number(widthParameterString);
881
896
  streamInfo.height = Number(heightParameterString);
882
897
  streamInfo.frameRate = frameRate || this.#getFrameRate(representation);
883
- if (supplementalProps && essentialProps) streamInfo.dynamicRange = parseDynamicRange(codecParameterString, supplementalProps, essentialProps);
898
+ if (supplementalProps && essentialProps) streamInfo.dynamicRange = parseDynamicRange(codecs, supplementalProps, essentialProps);
884
899
  } else if (streamInfo.type === "audio") {
885
900
  streamInfo.bitrate = bitrate;
886
901
  if (accessibilities) streamInfo.descriptive = checkIsDescriptive(accessibilities);
@@ -899,7 +914,7 @@ var DashExtractor = class DashExtractor {
899
914
  streamInfo.playlist.mediaParts.push(new MediaPart());
900
915
  streamInfo.periodId = periodId;
901
916
  streamInfo.groupId = representation.getAttribute("id");
902
- streamInfo.codecs = representation.getAttribute("codecs") || adaptationSet.getAttribute("codecs");
917
+ streamInfo.codecs = codecs;
903
918
  const volumeAdjust = representation.getAttribute("volumeAdjust");
904
919
  if (volumeAdjust) streamInfo.groupId = streamInfo.groupId + "-" + volumeAdjust;
905
920
  const mType = representation.getAttribute("mimeType") || adaptationSet.getAttribute("mimeType");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dasha",
3
- "version": "4.0.0-alpha.6",
3
+ "version": "4.0.0-alpha.8",
4
4
  "description": "Streaming manifest parser",
5
5
  "files": [
6
6
  "dist"