Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sound preference proposal, closes #83 #84

Merged
merged 12 commits into from
Mar 2, 2020
Merged

Sound preference proposal, closes #83 #84

merged 12 commits into from
Mar 2, 2020

Conversation

smarek
Copy link
Contributor

@smarek smarek commented Apr 7, 2019

No description provided.

@ubershmekel
Copy link
Owner

ubershmekel commented May 31, 2019

Thank you for doing this work! Two requests if you have time @smarek:

@smarek
Copy link
Contributor Author

smarek commented Jun 7, 2019

@ubershmekel cool

  1. fallback_url links directly the video, hls_url links m3u8 playlist, which is usually not very compatible with browsers, and I think we would have to integrate additional JS library to handle such playlists.
    Do you insist on replacing fallback_url with hls_url ?

This is what I see in media.reddit_video. block of JSON url you've linked, maybe the contents changes over time, and you've seen something very different?

"media": {
"reddit_video": {
"fallback_url": "https://v.redd.it/3fqsu5bczj131/DASH_720?source=fallback",
"height": 720,
"width": 1280,
"scrubber_media_url": "https://v.redd.it/3fqsu5bczj131/DASH_96",
"dash_url": "https://v.redd.it/3fqsu5bczj131/DASHPlaylist.mpd",
"duration": 61,
"hls_url": "https://v.redd.it/3fqsu5bczj131/HLSPlaylist.m3u8",
"is_gif": false,
"transcoding_status": "completed"
}
},
  1. yes, the layout is not very nice, and i've got no idea what to do with it, however that is something I can fix easily, once we agree on what design we want to have

I propose this controls layout:

subreddit link | nswf | sound | fullscreen
hotkeys | src | blog | comments | image
auto next form seconds
pagination

what do you think?

@ubershmekel
Copy link
Owner

  1. I'm not sure I understand your proposal. https://v.redd.it/3fqsu5bczj131/DASH_720?source=fallback has no audio as far as I can tell. Do you hear audio at that url?

  2. For layout, I'm thinking of separating the types of UI. First row would be links, the second would be the checkboxes.

redditp-info | subreddit link | comments | image
nsfw | sound | auto next | duration | fullscreen
pagination

Then redditp-info would link to the github readme. This would remove hotkeys | src | blog which would be explained and linked at the github readme.

What do you think of that layout?

js/script.js Outdated
@@ -334,6 +354,7 @@ $(function () {
// Need to redesign this redditp thing.
pic.type = imageTypes.gifv;
pic.url = pic.data.media.reddit_video.fallback_url;
pic.sound = pic.url.substring(0,pic.url.lastIndexOf('/'))+"/audio";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Audio url

@smarek
Copy link
Contributor Author

smarek commented Jun 8, 2019

  1. sorry, audio is available at fallback_url/audio see the script.js line 357
    No audio is on the media links, from the dog link you posted, if you look in network trace, you can see reddit is loading DASH video of specific quality (720p) and audio separately
    2019-06-08-092206_500x213_scrot

  2. I like it, my proposal tried to keep some things where they were, but if you're cool with complete reorg, i like it :)

…-sound2

# Conflicts:
#	index.html
#	js/EmbedIt.js
#	js/script.js

Note this only seems to work for video URLs that have sound in them. Not for recombining separate sound file with video file (like reddit). So it only works for imgur.
@ubershmekel
Copy link
Owner

I re-merged and tested this. This works for a file that has video+audio in it, but not for separate video and audio files like reddit videos. Seems only imgur and gfycat will work with this.

I think to make it fully work we'd need to implement something like this JS multiplexing. Which is what I assume reddit video has done: https://medium.com/canal-tech/how-video-streaming-works-on-the-web-an-introduction-7919739f7e1

I'm not sure if we should merge it in when reddit videos don't work.

@smarek
Copy link
Contributor Author

smarek commented Feb 6, 2020

Could you maybe create a branch on which we could propose PRs to fix remaining issues with sound, from mentioned "re-merged" branch you already have? Or if you have staging environment somewhere for others to test the sound with (if not, it can be disabled by default and listed under experimental options)

Also the "multiplexing" is imho not needed, as you can simply provide different URL that contains MP4 container (audio+video) , or provide separate <video and <audio html tags and sync them using https://stackoverflow.com/a/32323192/492624 or similar techniques

@ubershmekel
Copy link
Owner

ubershmekel commented Feb 6, 2020

https://github.com/ubershmekel/redditp/commits/smarek-sound2

You're right. Making separate elements would work too.

@smarek
Copy link
Contributor Author

smarek commented Feb 10, 2020

@ubershmekel before i start working on that, would you be cool with using dash.js for playing (json)reddit_video.dash_url instead of using plain html5 elements?

@ubershmekel
Copy link
Owner

I see the minified file is 577 KB (non-gzipped size). I couldn't find a browser compatibility matrix. Can you explain the cost-benefit? Seems a bit heavy and potentially fragile.

@smarek
Copy link
Contributor Author

smarek commented Feb 10, 2020

Given raw-json

"reddit_video": {
"fallback_url": "https://v.redd.it/iysd6l20k3941/DASH_480?source=fallback",
"height": 480,
"width": 384,
"scrubber_media_url": "https://v.redd.it/iysd6l20k3941/DASH_96",
"dash_url": "https://v.redd.it/iysd6l20k3941/DASHPlaylist.mpd",
"duration": 19,
"hls_url": "https://v.redd.it/iysd6l20k3941/HLSPlaylist.m3u8",
"is_gif": false,
"transcoding_status": "completed"
}

We can either do

  1. Plain html+js (whatever source data)
  2. dash.js (dash_url)
  3. hls.js (hls_url)
  4. ???
  5. (maybe we can do all of them, and fall-back through when given browser does not support one but supports other?)

I've found conflicted sources, but it seems to me that HLS, being Apple technology, has far more lower support than DASH

However reddit itself (on my device) opens with HLS source

<video poster="https://external-preview.redd.it/SZJwCdXt4knnZgskQuE2_C_QDyCXQeDNReuwC-lp5aw.png?width=320&amp;crop=smart&amp;format=pjpg&amp;auto=webp&amp;s=53e709f966bf326c52cb3b64b995cdb2525e2bd8" muted="" preload="auto" class="_1EQJpXY7ExS04odI1YBBlj" src="blob:https://www.reddit.com/b59eb125-a56e-46b4-9d40-9bd09d38b4c4">
<source src="https://v.redd.it/iysd6l20k3941/HLSPlaylist.m3u8" type="application/vnd.apple.mpegURL">
</video>

I'd be really grateful if someone could investigate the protocol compatibility between HLS/DASH

Relevant tickets

@smarek
Copy link
Contributor Author

smarek commented Feb 27, 2020

@ubershmekel I'm quite sorry, but I've solved this ticket and related #104 ticket, but the PR is quite a lot changes, because I was not able to develop efficiently, with so much code issues.

Changes i've included along (and the PR is currently mergable without conflicts against master)

  • ignoring idea (idea-community/webstorm/phpstorm) dev files
  • code formatting, terminating statements with ;, strict comparison in if statements
  • ability to handle single-post URL (useful for debugging)
  • fixed distinguish for json/jsonp requests
  • disable cloud reporting on non-production environment

I've left the commits un-squashed, but after review, if accepted, i can (or you can) squash some of them together

Also, since I've updated this PR and did not create new one against branch smarek-sound2, said branch can be deleted currently

@@ -435,7 +464,8 @@ $(function () {
$('#titleDiv .collapser').click();
break;
case A_KEY:
$("#autoNextSlide").prop("checked", !$("#autoNextSlide").is(':checked'));
var $ans = $("#autoNextSlide");
$ans.prop("checked", !$ans.is(':checked'));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is lint issue duplicate jquery selector

if (!rp.photos[i].over18) {
return i;
}
}
return 0;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here not handling situation where none of available pictures is non-nsfw caused ajax looping, but it's obscure usecase

index.html Outdated Show resolved Hide resolved
if (videoTags.length === 1) {
videoTags[0].muted = !rp.settings.sound;
}
var audioTags = document.getElementsByTagName('audio');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since for v.redd.it audio tag is separate from video tag, this needs to be checked as well

@@ -342,14 +370,15 @@ $(function () {
// some crossposts don't have a pic.data.media obj?
return;
}
pic.sound = pic.url.substring(0, pic.url.lastIndexOf('/')) + "/audio";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this generates audio link for v.redd.it links only

//log("skipped bad extension: " + url);
return false;
}
return rp.settings.goodExtensions.indexOf(extension) >= 0;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

simplify expression lint

return false;
}
}
return !!query.shuffle;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


};

var getStackTrace = function () {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

helper function, unused currently, but very useful in tracing dev issues

@@ -811,7 +850,8 @@ $(function () {
rp.session.loadingNextImages = true;

// Note that JSONP requests require `".json?jsonp=?"` here.
var jsonUrl = rp.redditBaseUrl + rp.subredditUrl + ".json?jsonp=?" + rp.session.after + "&" + getVars;
var jsonUrl = rp.redditBaseUrl + rp.subredditUrl + ".json?" + (rp.session.after ? rp.session.after + "&" : "") + getVars;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jsonp query attribute is added based on below useJsonP classification

@ubershmekel
Copy link
Owner

Looks like a lot of work. What's the state of affairs?

@smarek
Copy link
Contributor Author

smarek commented Feb 28, 2020

What do you mean?

Co-Authored-By: Yuval Greenfield <[email protected]>
@smarek
Copy link
Contributor Author

smarek commented Mar 1, 2020

If the single proposed change is everything, i think, it's ready to merge

@ubershmekel
Copy link
Owner

Looking at the code, this is all great stuff. I wish I had a test suite that could run through more scenarios. I hope to finish reviewing tomorrow.

@smarek
Copy link
Contributor Author

smarek commented Mar 1, 2020

Only thing I'm not satisfied with, is the detection of subreddits, that redirect.

There are certainly more than what's hard-coded currently, and I did not find any official list of this kind of subreddits, and detecting whether the call resulted in response from different subreddit (which might not be complete/best solution), is not possible via standard jQuery XHR means (currently being solved here jquery/jquery#4405 )

I propose to solve this in subsequent PR, because ie. r/random returns data from randomly picked subreddit, but currently implementation calls next page of items from url such as http://www.reddit.com/r/random.json?&after=t3_fap561& which is not correct obviously

// is the current solution sadly.
// Note we're still using `jsonp` despite potential issues because
// `http://www.redditp.com/r/randnsfw` wasn't working with CORS for some reason.
// https://github.com/ubershmekel/redditp/issues/104
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You removed this comment, without providing an explanation for the jsonp toggling or why did you make the following specific exceptions touseJsonP. We should pick this up in a future PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, it seemed to me that useJsonP with the code, that decides whether it's true or false, is pretty self-explanatory, but as I said, I expect this to be solved better when we tackle the redirected subreddits.

@ubershmekel
Copy link
Owner

I love that getting a /comments/ URL works now. I was hoping to get that fixed some day. I'm curious why you need to toggle between jsonp and not for specific URLs. I thought JSONP works for everything. No?

Merging. We'll get the rest sorted later. Thank you so much for all this work @smarek it works beautifully as far as I can tell.

@ubershmekel ubershmekel merged commit a060603 into ubershmekel:master Mar 2, 2020
@smarek
Copy link
Contributor Author

smarek commented Mar 2, 2020

I love that getting a /comments/ URL works now. I was hoping to get that fixed some day. I'm curious why you need to toggle between jsonp and not for specific URLs. I thought JSONP works for everything. No?

This is given by response type of the endpoint, when the request is redirected or single-post, the response type does not match application/json, and is blocked by CORB (at least in my chrome dev version 82)

Anyway, I'm glad you like the work, and you should probably delete the smarek-sound2 branch now

@smarek smarek deleted the sound branch March 2, 2020 06:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants