Skip to content

Commit ca3e845

Browse files
committed
Mention the new supported targets
1 parent cea7806 commit ca3e845

File tree

1 file changed

+81
-50
lines changed

1 file changed

+81
-50
lines changed

src/main.c

+81-50
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,49 @@ static void m3u8ds_free(struct M3U8DownloadedStreams* const streams) {
9191

9292
}
9393

94+
const struct M3U8StreamItem* m3u8stream_finditem(const struct M3U8Stream* const root, const struct M3U8Stream* const resource) {
95+
/*
96+
Look for a M3U8 item that matches the given M3U8 stream.
97+
*/
98+
99+
size_t index = 0;
100+
101+
if (root->playlist.type != M3U8_PLAYLIST_TYPE_MASTER) {
102+
return NULL;
103+
}
104+
105+
for (index = 0; index < root->offset; index++) {
106+
const struct M3U8StreamItem* const item = &root->items[index];
107+
108+
switch (item->type) {
109+
case M3U8_STREAM_VARIANT_STREAM: {
110+
const struct M3U8VariantStream* const variant_stream = item->item;
111+
112+
if (&variant_stream->stream != resource) {
113+
break;
114+
}
115+
116+
return item;
117+
}
118+
case M3U8_STREAM_MEDIA: {
119+
const struct M3U8Media* const media = item->item;
120+
121+
if (&media->stream != resource) {
122+
break;
123+
}
124+
125+
return item;
126+
}
127+
default: {
128+
break;
129+
}
130+
}
131+
}
132+
133+
return NULL;
134+
135+
}
136+
94137
int main(int argc, argv_t* argv[]) {
95138

96139
int err = M3U8ERR_SUCCESS;
@@ -116,6 +159,7 @@ int main(int argc, argv_t* argv[]) {
116159
int referer = 0;
117160
int insecure = 0;
118161
int debug = 0;
162+
int disable_autoselect = 0;
119163

120164
int select_all_medias = 0;
121165
int exists = 0;
@@ -744,6 +788,14 @@ int main(int argc, argv_t* argv[]) {
744788
goto end;
745789
}
746790
}
791+
792+
/*
793+
No media have been explicitly selected; let's select the ones attached to
794+
that variant stream.
795+
*/
796+
if (selected_medias.offset == 0 && !disable_autoselect) {
797+
798+
}
747799
}
748800

749801
break;
@@ -762,28 +814,28 @@ int main(int argc, argv_t* argv[]) {
762814
if (key != NULL) {
763815
for (index = 0; index < stream.offset; index++) {
764816
struct M3U8StreamItem* const item = &stream.items[index];
765-
struct M3U8Stream* substream = NULL;
817+
struct M3U8Stream* resource = NULL;
766818

767819
switch (item->type) {
768820
case M3U8_STREAM_VARIANT_STREAM: {
769-
substream = &((struct M3U8VariantStream*) item->item)->stream;
821+
resource = &((struct M3U8VariantStream*) item->item)->stream;
770822
break;
771823
}
772824
case M3U8_STREAM_MEDIA: {
773-
substream = &((struct M3U8Media*) item->item)->stream;
825+
resource = &((struct M3U8Media*) item->item)->stream;
774826
break;
775827
}
776828
default: {
777829
break;
778830
}
779831
}
780832

781-
if (substream == NULL) {
833+
if (resource == NULL) {
782834
continue;
783835
}
784836

785-
for (subindex = 0; subindex < substream->offset; subindex++) {
786-
struct M3U8StreamItem* const subitem = &substream->items[subindex];
837+
for (subindex = 0; subindex < resource->offset; subindex++) {
838+
struct M3U8StreamItem* const subitem = &resource->items[subindex];
787839
struct M3U8Segment* const segment = subitem->item;
788840
struct M3U8Attribute* attribute = NULL;
789841

@@ -816,8 +868,10 @@ int main(int argc, argv_t* argv[]) {
816868
}
817869

818870
for (index = 0; index < selected_streams.offset; index++) {
819-
struct M3U8Stream* const substream = selected_streams.items[index];
820-
name = malloc(strlen(temporary_directory) + strlen(PATHSEP) + uintlen((biguint_t) substream) + 1 + 4 + 1);
871+
const struct M3U8StreamItem* item = NULL;
872+
873+
struct M3U8Stream* const resource = selected_streams.items[index];
874+
name = malloc(strlen(temporary_directory) + strlen(PATHSEP) + uintlen((biguint_t) resource) + 1 + 4 + 1);
821875

822876
if (name == NULL) {
823877
err = M3U8ERR_MEMORY_ALLOCATE_FAILURE;
@@ -827,7 +881,7 @@ int main(int argc, argv_t* argv[]) {
827881
strcpy(name, temporary_directory);
828882
strcat(name, PATHSEP);
829883

830-
wsize = snprintf(name + strlen(name), 4096, "%"FORMAT_BIGGEST_UINT_T, (biguint_t) substream);
884+
wsize = snprintf(name + strlen(name), 4096, "%"FORMAT_BIGGEST_UINT_T, (biguint_t) resource);
831885

832886
if (wsize < 1) {
833887
err = M3U8ERR_PRINTF_WRITE_FAILURE;
@@ -838,58 +892,35 @@ int main(int argc, argv_t* argv[]) {
838892

839893
printf("- Download Stream #%zu\n", index);
840894

841-
switch (stream.playlist.type) {
842-
case M3U8_PLAYLIST_TYPE_MASTER: {
843-
844-
for (subindex = 0; subindex < stream.offset; subindex++) {
845-
const struct M3U8StreamItem* const item = &stream.items[subindex];
846-
847-
switch (item->type) {
848-
case M3U8_STREAM_VARIANT_STREAM: {
849-
const struct M3U8VariantStream* const variant_stream = item->item;
850-
851-
if (&variant_stream->stream != substream) {
852-
break;
853-
}
854-
855-
show_variant_stream(item);
856-
857-
break;
858-
}
859-
case M3U8_STREAM_MEDIA: {
860-
const struct M3U8Media* const media = item->item;
861-
862-
if (&media->stream != substream) {
863-
break;
864-
}
865-
866-
show_media(item);
867-
868-
break;
869-
}
870-
default: {
871-
break;
872-
}
873-
}
895+
item = m3u8stream_finditem(&stream, resource);
896+
897+
if (item == NULL) {
898+
show_media_playlist_metadata(resource);
899+
} else {
900+
switch (item->type) {
901+
case M3U8_STREAM_VARIANT_STREAM: {
902+
show_variant_stream(item);
903+
break;
904+
}
905+
case M3U8_STREAM_MEDIA: {
906+
show_media(item);
907+
break;
908+
}
909+
default: {
910+
break;
874911
}
875-
876-
break;
877-
}
878-
case M3U8_PLAYLIST_TYPE_MEDIA: {
879-
show_media_playlist_metadata(substream);
880-
break;
881912
}
882913
}
883914

884-
err = m3u8stream_download(&stream, substream, &download_options);
915+
err = m3u8stream_download(&stream, resource, &download_options);
885916

886917
if (err != M3U8ERR_SUCCESS) {
887918
goto end;
888919
}
889920

890921
printf("- Dumping Media Playlist to '%s'\n\n", name);
891922

892-
err = m3u8_dump_file(&substream->playlist, name);
923+
err = m3u8_dump_file(&resource->playlist, name);
893924

894925
if (err != M3U8ERR_SUCCESS) {
895926
goto end;

0 commit comments

Comments
 (0)